From d18f221a59fcf8ea0fc66c1565a0c61f8ef53abd Mon Sep 17 00:00:00 2001 From: Praveen Kumar <44535109+praveen-x@users.noreply.github.com> Date: Sun, 28 Oct 2018 04:11:58 +0530 Subject: [PATCH] Create Source Code to Find Hash --- Source Code to Find Hash | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Source Code to Find Hash diff --git a/Source Code to Find Hash b/Source Code to Find Hash new file mode 100644 index 0000000..d4db2ee --- /dev/null +++ b/Source Code to Find Hash @@ -0,0 +1,27 @@ +# Python rogram to find the SHA-1 message digest of a file + +# import 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)