Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from hashlib import sha256
- from time import sleep
- MAX_NONCE = 100000000000
- def SHA256(text):
- return sha256(text.encode("ascii")).hexdigest()
- def mine(block_number, transactions, previous_hash, prefix_zeros):
- prefix_str = '0'*prefix_zeros
- for nonce in range(MAX_NONCE):
- text = str(block_number) + transactions + previous_hash + str(nonce)
- new_hash = SHA256(text)
- if new_hash.startswith(prefix_str):
- print(f"Yay! Successfully mined bitcoins with nonce value:{nonce}")
- return new_hash
- raise BaseException(f"Couldn't find correct has after trying {MAX_NONCE} times")
- if __name__=='__main__':
- transactions='''
- Dhaval->Bhavin->20,
- Mando->Cara->45
- '''
- difficulty=4 # try changing this to higher number and you will see it will take more time for mining as difficulty increases
- import time
- start = time.time()
- sleep(3)
- print("started mining...")
- sleep(3)
- print("||")
- sleep(1)
- print("||")
- sleep(1)
- print("||")
- sleep(1)
- print("||")
- sleep(1)
- print("||")
- sleep(1)
- print("\/")
- sleep(2)
- new_hash = mine(5,transactions,'0000000a036944e29568d0cff17edbe038f81208fecf9a66be9a2b8321c6ec7', difficulty)
- sleep(2)
- total_time = str((time.time() - start))
- sleep(3)
- print(f"ending mining. Mining took: {total_time} seconds")
- sleep(2)
- print(new_hash)
Advertisement
Comments
-
- Link: https://replit.com
-
- Link v2: https://youtu.be/tSy5kESxHkU
- Link v3: https://uptimerobot.com/
-
- congrats on 26k veiws
-
- Yes
-
- cryptocurrency on roblox
-
- Code python to lua
-
- Execute cryptocurrency on roblox
Add Comment
Please, Sign In to add comment
Advertisement