1
0
mirror of https://github.com/bitcoinbook/bitcoinbook synced 2024-12-24 15:38:08 +00:00
bitcoinbook/code/hash_example.py
Manjeet Singh Bhatia 22e17ffd3c
Update hash_example.py
As input and hash are inbuilt functions, so I'd suggest using other names for variables.
here is output from python interpreter.

>>> hash
<built-in function hash>
>>> input
<built-in function input>
2017-12-09 22:05:50 -08:00

19 lines
458 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_data = text + str(nonce)
# calculate the SHA-256 hash of the input (text+nonce)
hash_data = hashlib.sha256(input_data).hexdigest()
# show the input and hash result
print input_data, '=>', hash_data