top of page
  • Writer's pictureVlad

[CodewithMe]Create a Program that would compute Hash from a File




We'll code on a program that would extract the equivalent hash from a file via Python, with the aid of hashlib module . We'll later validate the result by uploading the sample file in Virustotal.



Code:


import hashlib


filename = raw_input("File Name: ")


print "++++++++++"

print "HASH"

print "++++++++++"


print "SHA-1:",


sha1_file = hashlib.sha1()

with open(str(filename),'rb') as afile:

buff = afile.read()

sha1_file.update(buff)

new_sha1 = sha1_file.hexdigest()

print new_sha1



print "SHA-256:",

sha256_file = hashlib.sha256()

with open(str(filename),'rb') as afile:

buff = afile.read()

sha256_file.update(buff)

new_sha256 = sha256_file.hexdigest()

print new_sha256



print "MD5:",

md5_file = hashlib.md5()

with open(str(filename),'rb') as afile:

buff = afile.read()

md5_file.update(buff)

new_md5 = md5_file.hexdigest()

print new_md5



print "++++++++++"

print "Program Ends"


Click on this youtube video for the demo

https://youtu.be/Z1AMMr1uPUQ


8 views0 comments

Recent Posts

See All

LET'S TAKE IT TO THE NEXT LEVEL!

bottom of page