From fe98460293ee69a55e7737aa026b1c0260995b88 Mon Sep 17 00:00:00 2001 From: Adityan__Dinesh <68809278+AdityanDinesh@users.noreply.github.com> Date: Wed, 20 Oct 2021 16:25:20 +0530 Subject: [PATCH] Create find_hash.py --- Code/Python/find_hash.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Code/Python/find_hash.py diff --git a/Code/Python/find_hash.py b/Code/Python/find_hash.py new file mode 100644 index 0000000..1ee3500 --- /dev/null +++ b/Code/Python/find_hash.py @@ -0,0 +1,27 @@ +# Python rogram to find the SHA-1 message digest of a file + +# importing the hashlib module +import hashlib + +def hash_file(filename): + """"This function returns the SHA-1 hash + of the file passed into it""" + + # make a hash object + h = hashlib.sha1() + + # open file for reading in binary mode + with open(filename,'rb') as file: + + # loop till the end of the file + chunk = 0 + while chunk != b'': + # read only 1024 bytes at a time + chunk = file.read(1024) + h.update(chunk) + + # return the hex representation of digest + return h.hexdigest() + +message = hash_file("track1.mp3") +print(message)