Skip to content

Instantly share code, notes, and snippets.

@fintara
Created November 29, 2019 19:31
Show Gist options
  • Save fintara/c30673b3939ac0d2b99a86c12d4e782a to your computer and use it in GitHub Desktop.
Save fintara/c30673b3939ac0d2b99a86c12d4e782a to your computer and use it in GitHub Desktop.
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