1
0
mirror of https://github.com/bitcoinbook/bitcoinbook synced 2025-02-11 15:13:09 +00:00
bitcoinbook/code/hash_example.py
Andreas M. Antonopoulos e22fbe65cc import of first edition
2015-11-22 09:57:54 -06:00

18 lines
432 B
Python

# example of iterating a nonce in a hashing algorithm's input
import hashlib
text = "I am Satoshi Nakamoto"
# iterate nonce from 0 to 19
for nonce in xrange(20):
# add the nonce to the end of the text
input = text + str(nonce)
# calculate the SHA-256 hash of the input (text+nonce)
hash = hashlib.sha256(input).hexdigest()
# show the input and hash result
print input, '=>', hash