mirror of
https://github.com/bitcoinbook/bitcoinbook
synced 2024-11-25 01:18:18 +00:00
fixed hashlib library error for python3
This commit is contained in:
parent
f8b883dcd4
commit
d70a0f91f2
@ -12,7 +12,7 @@ for nonce in range(20):
|
||||
input_data = text + str(nonce)
|
||||
|
||||
# calculate the SHA-256 hash of the input (text+nonce)
|
||||
hash_data = hashlib.sha256(input_data).hexdigest()
|
||||
hash_data = hashlib.sha256(input_data.encode()).hexdigest()
|
||||
|
||||
# show the input and hash result
|
||||
print(input_data, '=>', hash_data)
|
||||
|
@ -19,7 +19,7 @@ def proof_of_work(header, difficulty_bits):
|
||||
target = 2 ** (256 - difficulty_bits)
|
||||
|
||||
for nonce in xrange(max_nonce):
|
||||
hash_result = hashlib.sha256(str(header) + str(nonce)).hexdigest()
|
||||
hash_result = hashlib.sha256((str(header) + str(nonce)).encode()).hexdigest()
|
||||
|
||||
# check if this is a valid result, below the target
|
||||
if long(hash_result, 16) < target:
|
||||
|
Loading…
Reference in New Issue
Block a user