mirror of
https://github.com/bitcoinbook/bitcoinbook
synced 2024-11-15 12:39:01 +00:00
2f0d7d8c3a
The commit ab5ae32bae
is the last commit
for the second edition, so all changes since then are dropped except for
several commits for the third edition authored by Andreas Antonopoulos.
No attempt is made to remove CC-BY-SA or other licensed content present
in the already-published first or second editions.
This revert may itself be reverted for versions of the book published
under CC-BY-SA.
19 lines
473 B
Python
19 lines
473 B
Python
# example of iterating a nonce in a hashing algorithm's input
|
|
|
|
from __future__ import print_function
|
|
import hashlib
|
|
|
|
text = "I am Satoshi Nakamoto"
|
|
|
|
# iterate nonce from 0 to 19
|
|
for nonce in range(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)
|