![](https://static.wixstatic.com/media/fcac84_5ed6d032fe2b428b818dea535ebc43c5~mv2.png/v1/fill/w_980,h_551,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/fcac84_5ed6d032fe2b428b818dea535ebc43c5~mv2.png)
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
Comments