473,320 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

md5 wrongness?


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
4 1112
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

111
by: JKop | last post by:
Okay here we go, I feel it's about time people conversed about the bullshit aspects of C++ (including the bullshit stuff brought forward from C). I'll begin with a few of my own grievances: 1)...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
35
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
12
by: Troy | last post by:
My ISP provides me with 2 servers: one for normal web hosting (non-PHP) and a CGI server (with PHP). I create my website using fusion 7 and upload this in its entirity to the web hosting server....
28
by: prunoki | last post by:
Hello, I am an SQL server newbie. Our company has a massive application written in PL/SQL. I need to port parts of it to SQL Server. - Which SQL server version should I choose, to have a...
143
by: suri | last post by:
Hello I downloaded glibc and tried looking for the code that implements the sine function i couldnt find the file. i went to the math directory and found math.h.. i guess that needs to be...
43
by: Dave Vandervies | last post by:
Seen in a chunk of code I was looking at recently (not mine!): -------- char* imgfilename; sprintf((char*)imgfilename, "mask%d.dib", params.profile); ReadImage((char*)imgfilename); --------...
9
by: QQ | last post by:
Hello I have a string like this "213200","0000","9999","204-033-105" but I need to seperate them to be s1 = 213200; s2 = 0000; s3 = 9999; s4 = 204-033-105; Is there any good way to do it?
67
by: Scott M. | last post by:
Can anyone give me any ideas on why VS.NET 2003 running on XP Pro. (P4's with 1GB RAM) would take over 3 minutes to simply create a new ASP.NET Web Application on http://localhost? It seems that...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.