470,815 Members | 1,321 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

wired md5 hashing problem

Hello list-members

i am in the process of writing a python script to backup my data. Now I
would like to implement md5/sha1 hashes.

# do md5 fingerprinting
if config.get("global", "crc") == "md5":
m = md5.new()
# open the file
f = open(fname, "rb")
while 1:
block = f.read(1024*1024)
if not block:
break
# generate the hash
m.update(block)
f.close()

# write the results properly formated to a file
fd = file(fname + ".md5", "w")
fd.write(m.hexdigest())
fd.write(" " + fname + "\n")
fd.close()
mguentert@uranos > md5sum -c backup.tar.bz2.md5
/fileservice/temp/backup.tar.bz2: FAILED
md5sum: WARNING: 1 of 1 computed checksum did NOT match

mguentert@uranos > cat backup.tar.bz2.md5
d41d8cd98f00b204e9800998ecf8427e /fileservice/temp/backup.tar.bz2

so the format should be okay, but whats wrong with my piece of code?!

Greetings

--
Mit freundlichen Grüßen

Matthias Güntert

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (GNU/Linux)

iD8DBQBEJquauQEWmvzea70RArn0AKC+ktZwzHUcXY+qqgN+Yj 50p5ilzACdE7X5
+apebd9xy1GCHeRGhHbw3Hc=
=ZDGF
-----END PGP SIGNATURE-----

Mar 26 '06 #1
1 974
Matthias Güntert <Ma***********@gmx.de> writes:
i am in the process of writing a python script to backup my data. Now I
would like to implement md5/sha1 hashes.
Try editing as follows: change
f = open(fname, "rb")
while 1:
block = f.read(1024*1024)
if not block:
break
# generate the hash
m.update(block)
f.close()


to:

f = open(fname, "rb")
nbytes = 0
while 1:
block = f.read(1024*1024)
nbytes += len(block)
if not block:
break
# generate the hash
m.update(block)
f.close()
print '%d bytes processed'

As Adam DePrince noticed, the md5 checksum you generated was that of
an empty file. So the above should tell you whether you're actually
processing any input; if you don't get the expected number of bytes,
debug from there.
Mar 26 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jocab | last post: by
1 post views Thread by snowteo | last post: by
11 posts views Thread by Wm. Scott Miller | last post: by
10 posts views Thread by Dino M. Buljubasic | last post: by
19 posts views Thread by Ole Nielsby | last post: by
8 posts views Thread by Maya | last post: by
6 posts views Thread by dmcglynn | last post: by
1 post views Thread by Tinku | last post: by
11 posts views Thread by January Weiner | last post: by
15 posts views Thread by Vinodh | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.