Problem Given the target file f0 and candidate files f1-f20, there is an identical copy of f0 among the files f1-f20. Write a python program to perform the following tasks: · Read in each file and calculate the hex hash values by using SHA3 function with the length of 512 for all the given files f0, f1-f20. · Save the hex hash values of each file as a new line in a .txt file named hash.txt file. · Read hash values from hash.txt and compare them to find the identical copy of f0 among f1-f20. · Write the finding result (the matched file name) back to hash.txt Submission • Name your project fileHash.py and submit both fileHash.py and hash.txt on Blackboard. • The program should be properly documented. • The program should have user friendly Input/Output design • Duplicate work (or obviously similar one) will result in an F grade in the course. Grading 1. Include comments as specified in the course syllabus. (10%) 2. Source code and results. · Correctness (70%) · User-friendliness in I/O design (10%) · Efficiency of the code (10%) Sample Code The following code is an example of reading a file and calculate the hash value of the file by using SHA2 function with the length of 256 import hashlib file_path = input("Enter the file path: ") BLOCK_SIZE = 65536 hash_handler = hashlib.sha256() with open(file_path, 'rb') as f: fb = f.read(BLOCK_SIZE) while fb: hash_handler.update(fb) fb = f.read(BLOCK_SIZE) file_hexhash = hash_handler.hexdigest() print(f"{file_path} file hash value: \n{file_hexhash}"
Problem
Given the target file f0 and candidate files f1-f20, there is an identical copy of f0 among the files f1-f20.
Write a python program to perform the following tasks:
· Read in each file and calculate the hex hash values by using SHA3 function with the length of 512 for all the given files f0, f1-f20.
· Save the hex hash values of each file as a new line in a .txt file named hash.txt file.
· Read hash values from hash.txt and compare them to find the identical copy of f0 among f1-f20.
· Write the finding result (the matched file name) back to hash.txt
Submission
• Name your project fileHash.py and submit both fileHash.py and hash.txt on Blackboard.
• The program should be properly documented.
• The program should have user friendly Input/Output design
• Duplicate work (or obviously similar one) will result in an F grade in the course.
Grading
1. Include comments as specified in the course syllabus. (10%)
2. Source code and results.
· Correctness (70%)
· User-friendliness in I/O design (10%)
· Efficiency of the code (10%)
Sample Code
The following code is an example of reading a file and calculate the hash value of the file by using SHA2 function with the length of 256
import hashlib file_path = input("Enter the file path: ")
BLOCK_SIZE = 65536 hash_handler = hashlib.sha256() with open(file_path, 'rb') as f: fb = f.read(BLOCK_SIZE) while fb: hash_handler.update(fb) fb = f.read(BLOCK_SIZE) file_hexhash = hash_handler.hexdigest() print(f"{file_path} file hash value: \n{file_hexhash}"
Step by step
Solved in 2 steps with 2 images