1
0
mirror of https://github.com/bitcoinbook/bitcoinbook synced 2024-11-01 04:58:59 +00:00
bitcoinbook/code/hash_example.py

19 lines
432 B
Python
Raw Normal View History

2013-08-18 22:35:38 +00:00
# example of iterating a nonce in a hashing algorithm's input
import hashlib
text = "I am Satoshi Nakamoto"
2014-09-25 16:02:07 +00:00
# iterate nonce from 0 to 19
2017-08-24 16:22:28 +00:00
for nonce in range(20):
2014-09-25 16:02:07 +00:00
# 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
2017-08-24 16:22:28 +00:00
print(input, '=>', hash)