From d70a0f91f2f89ef898673623abc34ac60e46362f Mon Sep 17 00:00:00 2001 From: koshikraj Date: Fri, 16 Mar 2018 20:32:21 +0530 Subject: [PATCH] fixed hashlib library error for python3 --- code/hash_example.py | 2 +- code/proof-of-work-example.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code/hash_example.py b/code/hash_example.py index d5e69b2b..977671bf 100644 --- a/code/hash_example.py +++ b/code/hash_example.py @@ -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) diff --git a/code/proof-of-work-example.py b/code/proof-of-work-example.py index 0431fedf..2415cd55 100755 --- a/code/proof-of-work-example.py +++ b/code/proof-of-work-example.py @@ -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: