I am iterating through a folder containing binary files and am trying to compute for each file's hash values, specifically sha1 and sha256. On my runs, I weirdly get the same sha256 values for all files, but the sha1 values are different (thus correct).
Below is a screenshot of an output file which shows sha1 hashing was done correctly. But sha256 isn't. (Sorry filenames of each binary file is also its sha1)
Is there something wrong with my process? This is the relevant code in Python. I AM NOT SEEING SOMETHING. Sorry.
out.write("FILENAME,SHA1,SHA256\n")
for root, dirs, files in os.walk(input_path):
for ffile in files:
myfile = os.path.join(root, ffile)
nice = os.path.join(os.getcwd(), myfile)
fo = open(nice, "rb")
a = hashlib.sha1(fo.read())
b = hashlib.sha256(fo.read())
paylname = os.path.basename(myfile)
mysha1 = str(a.hexdigest())
mysha256 = str(b.hexdigest())
fo.close()
out.write("{0},{1},{2}\n".format(paylname, mysha1, mysha256))