From f1c8b794125447b7f79260ae8587de2195dfb1d4 Mon Sep 17 00:00:00 2001 From: Govind Mohan Date: Mon, 26 Aug 2019 10:49:43 -0400 Subject: [PATCH] updated code to python 3.7 --- MerkleTrees.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/MerkleTrees.py b/MerkleTrees.py index 15c0f34..2213126 100644 --- a/MerkleTrees.py +++ b/MerkleTrees.py @@ -33,11 +33,11 @@ def create_tree(self): current_right = '' # 3.5 Apply the Hash 256 function to the current values - current_hash = hashlib.sha256(current) + current_hash = hashlib.sha256(current.encode()) # 3.6 If the current right hash is not a '' <- empty string if current_right != '': - current_right_hash = hashlib.sha256(current_right) + current_right_hash = hashlib.sha256(current_right.encode()) # 3.7 Add the Transaction to the dictionary past_transaction[listoftransaction[index]] = current_hash.hexdigest() @@ -68,7 +68,7 @@ def Get_past_transacion(self): # 5. Get the root of the transaction def Get_Root_leaf(self): - last_key = self.past_transaction.keys()[-1] + last_key = list(self.past_transaction.keys())[-1] return self.past_transaction[last_key] # Declare the main part of the function to run @@ -90,24 +90,24 @@ def Get_Root_leaf(self): past_transaction = Jae_Tree.Get_past_transacion() # f) Get the last transaction and print all - print "First Example - Even number of transaction Merkel Tree" - print 'Final root of the tree : ',Jae_Tree.Get_Root_leaf() + print("First Example - Even number of transaction Merkel Tree") + print('Final root of the tree : ',Jae_Tree.Get_Root_leaf()) print(json.dumps(past_transaction, indent=4)) - print "-" * 50 + print("-" * 50) # h) Second example - print "Second Example - Odd number of transaction Merkel Tree" + print("Second Example - Odd number of transaction Merkel Tree") Jae_Tree = Jae_MerkTree() transaction = ['a','b','c','d','e'] Jae_Tree.listoftransaction = transaction Jae_Tree.create_tree() past_transaction = Jae_Tree.Get_past_transacion() - print 'Final root of the tree : ',Jae_Tree.Get_Root_leaf() + print('Final root of the tree : ',Jae_Tree.Get_Root_leaf()) print(json.dumps(past_transaction, indent=4)) - print "-" * 50 + print("-" * 50) # i) Actual Use Case - print "Final Example - Actuall use case of the Merkle Tree" + print("Final Example - Actuall use case of the Merkle Tree") # i-1) Declare a transaction - the ground truth ground_truth_Tree = Jae_MerkTree() @@ -126,19 +126,19 @@ def Get_Root_leaf(self): tampered_Tree_root = tampered_Tree.Get_Root_leaf() # i-3) The three company share all of the transaction - print 'Company A - my final transaction hash : ',ground_truth_root - print 'Company B - my final transaction hash : ',ground_truth_root - print 'Company C - my final transaction hash : ',tampered_Tree_root + print('Company A - my final transaction hash : ',ground_truth_root) + print('Company B - my final transaction hash : ',ground_truth_root) + print('Company C - my final transaction hash : ',tampered_Tree_root) # i-4) Print out all of the past transaction - print "\n\nGround Truth past Transaction " + print("\n\nGround Truth past Transaction ") print(json.dumps(ground_truth_past_transaction, indent=4)) - print "\n\nTamper Truth past Transaction " + print("\n\nTamper Truth past Transaction ") print(json.dumps(tampered_Tree_past_transaction, indent=4)) -# ---- END OF THE CODE ------ \ No newline at end of file +# ---- END OF THE CODE ------