By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,846 Members | 1,872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,846 IT Pros & Developers. It's quick & easy.

md5 wrongness?

P: n/a

Why do Python's md5 and GNU md5sum produce differing results?

$ md5sum --version
md5sum (GNU coreutils) 5.97

$ echo snagglefrob | md5sum
f842244d79af85b457811091319d85ff -
$ echo 'snagglefrob' | md5sum
f842244d79af85b457811091319d85ff -
$ echo "snagglefrob" | md5sum
f842244d79af85b457811091319d85ff -
$ python
Python 2.4.4 (#2, Aug 16 2007, 02:03:40)
[GCC 4.1.3 20070812 (prerelease) (Debian 4.1.2-15)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>import md5
s = md5.new()
s.update('snagglefrob')
s.hexdigest()
'9eb2459fcdd9f9b8a9fef7348bcac933'

--
Ron Johnson, Jr.
Jefferson LA USA

%SYSTEM-F-FISH, my hovercraft is full of eels
Nov 24 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Ron Johnson wrote:
$ echo "snagglefrob" | md5sum
f842244d79af85b457811091319d85ff -

$ python
Python 2.4.4 (#2, Aug 16 2007, 02:03:40)
[GCC 4.1.3 20070812 (prerelease) (Debian 4.1.2-15)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>import md5
s = md5.new()
s.update('snagglefrob')
s.hexdigest()
'9eb2459fcdd9f9b8a9fef7348bcac933'
echo inserts a newline, your Python snippet doesn't.

% echo -n "snagglefrob" | md5sum
9eb2459fcdd9f9b8a9fef7348bcac933 -

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
Granted that I must die, how shall I live?
-- Michael Novak
Nov 24 '07 #2

P: n/a
On Nov 24, 1:34 pm, Ron Johnson <ron.l.john...@cox.netwrote:
Why do Python's md5 and GNU md5sum produce differing results?
They don't differ. Try feeding them the same input:
>>import md5
md5.new('snagglefrob').hexdigest()
'9eb2459fcdd9f9b8a9fef7348bcac933'
>>md5.new('snagglefrob\n').hexdigest()
'f842244d79af85b457811091319d85ff'
>>>
>
$ md5sum --version
md5sum (GNU coreutils) 5.97

$ echo snagglefrob | md5sum
f842244d79af85b457811091319d85ff -
$ echo 'snagglefrob' | md5sum
f842244d79af85b457811091319d85ff -
$ echo "snagglefrob" | md5sum
f842244d79af85b457811091319d85ff -

$ python
Python 2.4.4 (#2, Aug 16 2007, 02:03:40)
[GCC 4.1.3 20070812 (prerelease) (Debian 4.1.2-15)] on linux2
Type "help", "copyright", "credits" or "license" for more information.>>import md5
>s = md5.new()
s.update('snagglefrob')
s.hexdigest()

'9eb2459fcdd9f9b8a9fef7348bcac933'

--
Ron Johnson, Jr.
Jefferson LA USA

%SYSTEM-F-FISH, my hovercraft is full of eels
Nov 24 '07 #3

P: n/a
John Machin wrote:
On Nov 24, 1:34 pm, Ron Johnson <ron.l.john...@cox.netwrote:
>Why do Python's md5 and GNU md5sum produce differing results?

They don't differ. Try feeding them the same input:
>>>import md5
md5.new('snagglefrob').hexdigest()
'9eb2459fcdd9f9b8a9fef7348bcac933'
>>>md5.new('snagglefrob\n').hexdigest()
'f842244d79af85b457811091319d85ff'
>>>>
Or, alternatively:

$ echo -n snagglefrob | md5sum
9eb2459fcdd9f9b8a9fef7348bcac933 -

--
Ayaz Ahmed Khan
Nov 24 '07 #4

P: n/a
On 11/24/07 02:27, Ayaz Ahmed Khan wrote:
John Machin wrote:
>On Nov 24, 1:34 pm, Ron Johnson <ron.l.john...@cox.netwrote:
>>Why do Python's md5 and GNU md5sum produce differing results?
They don't differ. Try feeding them the same input:
>>>>import md5
md5.new('snagglefrob').hexdigest()
'9eb2459fcdd9f9b8a9fef7348bcac933'
>>>>md5.new('snagglefrob\n').hexdigest()
'f842244d79af85b457811091319d85ff'

Or, alternatively:

$ echo -n snagglefrob | md5sum
9eb2459fcdd9f9b8a9fef7348bcac933 -
Thanks to all. I knew there had to be operator error, but I
couldn't figure out where...

--
Ron Johnson, Jr.
Jefferson LA USA

%SYSTEM-F-FISH, my hovercraft is full of eels
Nov 24 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.