Reputation: 519
hi this code generate sha1 hash but hash differ from other tools generate sha1 hash from this file:
import os
import hashlib
fileList = os.listdir("D:\\a\\")
for i in fileList:
d=(hashlib.sha1(file("D:\\a\\"+i, 'r').read()).hexdigest())
# os.rename(i,d)
print(d)
in MD5 so i have this problem!! why?
edit: 'rb' solve my problem
Upvotes: 1
Views: 5201
Reputation: 11
import os
import hashlib
fileList = os.walk("c:\\temp")
for tuple in fileList:
for item in tuple[2]:
d = hashlib.md5(file(tuple[0] + "\\" + item, 'r').read()).hexdigest()
print [item, d]
Upvotes: 1
Reputation: 1754
Try using 'rb' and also try using the md5 method - at present you are using SHA1 - which is a different algorithm, and I presume from your explanation that the other tools are using md5.
Upvotes: 8