Skip to content

Instantly share code, notes, and snippets.

@bourdeau
Created January 9, 2018 08:35
Show Gist options
  • Select an option

  • Save bourdeau/d2d15bf5c1e4b7d4b3eea5d71388c8d6 to your computer and use it in GitHub Desktop.

Select an option

Save bourdeau/d2d15bf5c1e4b7d4b3eea5d71388c8d6 to your computer and use it in GitHub Desktop.
import sys
import hashlib
difficulty = 8
block = "alice:0.0001:bob:whatever"
nonce = 0
zeros = ""
for i in range(difficulty):
zeros += "0"
while True:
hash_object = hashlib.sha256('{}:{}'.format(block, nonce))
hash = hash_object.hexdigest()
if hash.startswith(zeros):
print('Difficulty: {}'.format(difficulty))
print('Hash: {}'.format(hash))
print('Nonce: {}'.format(nonce))
sys.exit(0)
nonce += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment