From 71853896838ed14f9b854e24e689f185d10084d7 Mon Sep 17 00:00:00 2001 From: Spekulaas Date: Mon, 18 Sep 2023 16:31:41 +0200 Subject: [PATCH] completed test exc --- .../FileComparison_a_t.py | 13 +++++++++---- .../{ => files}/original.png | Bin .../{ => files/received}/copy(1).png | Bin .../{ => files/received}/copy(2).png | Bin .../{ => files/received}/copy(3).png | Bin .../{ => files/received}/copy(4).png | Bin 6 files changed, 9 insertions(+), 4 deletions(-) rename period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/{ => files}/original.png (100%) rename period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/{ => files/received}/copy(1).png (100%) rename period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/{ => files/received}/copy(2).png (100%) rename period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/{ => files/received}/copy(3).png (100%) rename period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/{ => files/received}/copy(4).png (100%) diff --git a/period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/FileComparison_a_t.py b/period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/FileComparison_a_t.py index b84afe3..b9c1b7a 100644 --- a/period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/FileComparison_a_t.py +++ b/period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/FileComparison_a_t.py @@ -18,7 +18,7 @@ To test run 'FileComparison.py' in your command line Notes: * do not change class structure or method signature to not break unit tests * visit this url for more information on this topic: - https://home.cs.colorado.edu/~jrblack/papers/cbh.html + https://home.cs.colorado.edu/~jrblack1/papers/cbh.html """ from cryptography.hazmat.primitives import hashes from os import listdir @@ -33,7 +33,11 @@ with open(path + '/original.png', 'rb') as original_file: # TODO 1: Find the hash of the original file # use SHA256() hash function -original_hash = None # you need to modify this +# original_hash = +# has original file +original_hash = hashes.Hash(hashes.SHA256()) +original_hash.update(content) +original_hash = original_hash.finalize() file_list = [f for f in listdir(path + '/received/') if isfile(join(path + '/received/', f))] @@ -47,8 +51,9 @@ for f in file_list: with open(path + '/received/' + f, 'rb') as copy_file: content = copy_file.read() - hash = f # you need to modify this - + hash = hashes.Hash(hashes.SHA256()) + hash.update(content) + hash = hash.finalize() if hash == original_hash: print(f, 'is original!') else: diff --git a/period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/original.png b/period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/files/original.png similarity index 100% rename from period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/original.png rename to period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/files/original.png diff --git a/period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/copy(1).png b/period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/files/received/copy(1).png similarity index 100% rename from period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/copy(1).png rename to period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/files/received/copy(1).png diff --git a/period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/copy(2).png b/period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/files/received/copy(2).png similarity index 100% rename from period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/copy(2).png rename to period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/files/received/copy(2).png diff --git a/period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/copy(3).png b/period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/files/received/copy(3).png similarity index 100% rename from period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/copy(3).png rename to period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/files/received/copy(3).png diff --git a/period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/copy(4).png b/period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/files/received/copy(4).png similarity index 100% rename from period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/copy(4).png rename to period_1/04-blockchain_class/403_T03_A03_Hash_File_Comparison/files/received/copy(4).png