forked from codehouseindia/Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFind Hash of File
More file actions
29 lines (22 loc) · 741 Bytes
/
Find Hash of File
File metadata and controls
29 lines (22 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# https://www.facebook.com/ayush.aryan.790693/posts/458250045138646
# suscribed by Ayush Aryan
# 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)