Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create find_hash.py #485

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Code/Python/find_hash.py
Original file line number Diff line number Diff line change
@@ -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)