Created
November 29, 2019 19:31
-
-
Save fintara/c30673b3939ac0d2b99a86c12d4e782a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
import time | |
text = "Hello World!" | |
nonce = 0 | |
difficulty = "0" | |
start = time.time() | |
print("Nonce".ljust(16) + "Hash".ljust(70) + "Time") | |
while True: | |
value = str(nonce) + text | |
hash = hashlib.sha256(value.encode("utf-8")).hexdigest() | |
if hash[0:len(difficulty)] == difficulty: | |
elapsed = time.time() - start | |
print(str(nonce).ljust(16) + hash.ljust(70) + str(elapsed)) | |
difficulty = difficulty + "0" | |
nonce = nonce + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment