niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » python
wired md5 hashing problem
Post new topic   Reply to topic Page 1 of 1 [6 Posts] View previous topic :: View next topic
Author Message
Paul Rubin
*nix forums Guru


Joined: 28 Feb 2005
Posts: 1197

PostPosted: Sun Mar 26, 2006 8:30 pm    Post subject: Re: wired md5 hashing problem Reply with quote

Matthias Güntert <MatzeGuentert@gmx.de> writes:
Quote:
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

Quote:
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.
Back to top
Matthias Güntert
*nix forums beginner


Joined: 26 Mar 2006
Posts: 2

PostPosted: Sun Mar 26, 2006 5:31 pm    Post subject: Re: wired md5 hashing problem Reply with quote

On Sun, 2006-03-26 at 11:48 -0500, Adam DePrince wrote:
Quote:

What do you get when you type

md5sum backup.tar.bz2?

it is working. Don't know what went wrong. But now I have another
question: How am I able to execute an external program, like mysqldump?
I had a look into the mysql module it didn't fit my needs.

--
Mit freundlichen Grüßen

Matthias Güntert
Back to top
adam.deprince@gmail.com
*nix forums beginner


Joined: 24 Mar 2006
Posts: 21

PostPosted: Sun Mar 26, 2006 4:57 pm    Post subject: Re: wired md5 hashing problem Reply with quote

On Sun, 2006-03-26 at 16:56 +0200, Matthias Güntert wrote:
Quote:
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


Hey, I found an md5 collision for your file!

Quote:
import md5
md5.new().hexdigest()
'd41d8cd98f00b204e9800998ecf8427e'

[adam@localhost Include]$ md5sum # hit ^d at start

d41d8cd98f00b204e9800998ecf8427e -

Your file was empty when scanned.

Without more information, I'd say that your file was empty when you ran
your python code.

But your code does work ...

import md5
m = md5.new()
# open the file
fname="Python-2.4.2.tar.bz2"
f = open(fname, "rb" )
while 1:
block = f.read(1024*1024)
if not block:
break
# generate the hash
m.update(block)
f.close()
fd = file(fname + ".md5", "w")
fd.write(m.hexdigest())
fd.write(" " + fname + "\n")
fd.close()

[adam@localhost ~]$ python test2.py
[adam@localhost ~]$ md5sum -c Python-2.4.2.tar.bz2.md5
Python-2.4.2.tar.bz2: OK

- Adam
Back to top
adam.deprince@gmail.com
*nix forums beginner


Joined: 24 Mar 2006
Posts: 21

PostPosted: Sun Mar 26, 2006 4:48 pm    Post subject: Re: wired md5 hashing problem Reply with quote

What do you get when you type

md5sum backup.tar.bz2?

- Adam

On Sun, 2006-03-26 at 16:56 +0200, Matthias Güntert wrote:
Quote:
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

--
http://mail.python.org/mailman/listinfo/python-list
Back to top
Felipe Almeida Lessa
*nix forums Guru Wannabe


Joined: 11 Feb 2006
Posts: 147

PostPosted: Sun Mar 26, 2006 2:59 pm    Post subject: Re: wired md5 hashing problem Reply with quote

Em Dom, 2006-03-26 às 16:56 +0200, Matthias Güntert escreveu:
Quote:
so the format should be okay, but whats wrong with my piece of code?!

It looks ok for me. What does md5sum gives as the sum?

--
Felipe.
Back to top
Matthias Güntert
*nix forums beginner


Joined: 26 Mar 2006
Posts: 2

PostPosted: Sun Mar 26, 2006 2:56 pm    Post subject: wired md5 hashing problem Reply with quote

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
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [6 Posts] View previous topic :: View next topic
The time now is Sat Nov 22, 2008 9:55 am | All times are GMT
navigation Forum index » Programming » python
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Unknown in header problem -SOLVED- Light Speed Postfix 0 Thu Jul 03, 2008 10:40 am
No new posts problem with sending mail nuxia Postfix 0 Mon Apr 21, 2008 3:58 am
No new posts Postfix 2.3.8 Virtual problem Blotto Postfix 0 Fri Apr 04, 2008 6:11 am
No new posts Postfix sending problem for local domain remote email monkey_magix Postfix 0 Mon Sep 10, 2007 10:17 am
No new posts bounce problem murkis Postfix 0 Sun Oct 08, 2006 3:45 pm

Mortgage Calculator | Xbox Mod Chip | Yahoo Personals | Loans | Credit Cards
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.3793s ][ Queries: 20 (0.2817s) ][ GZIP on - Debug on ]