completed test exc

This commit is contained in:
Ryan Bakkes 2023-09-18 16:31:41 +02:00
parent 4ce6843788
commit 7185389683
6 changed files with 9 additions and 4 deletions

View File

@ -18,7 +18,7 @@ To test run 'FileComparison.py' in your command line
Notes: Notes:
* do not change class structure or method signature to not break unit tests * do not change class structure or method signature to not break unit tests
* visit this url for more information on this topic: * 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 cryptography.hazmat.primitives import hashes
from os import listdir 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 # TODO 1: Find the hash of the original file
# use SHA256() hash function # 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))] 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: with open(path + '/received/' + f, 'rb') as copy_file:
content = copy_file.read() 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: if hash == original_hash:
print(f, 'is original!') print(f, 'is original!')
else: else: