Hi
I noticed that the md5 computed with md5 module from python is
different then the md5 sum computed with md5sum utility (on slackware
and gentoo).
i.e.
$echo marius|md5sum
0f0f60ac801a9eec2163083a22307deb - test = md5.new("marius") print test.hexdigest()
242aa1a97769109065e3b4df359bcfc9
Any idea why? and how to get the same md5 sum for both calls?
Thanks 9 1766
In article <11**********************@j73g2000cwa.googlegroups .com>,
"ur************@gmail.com" <ur************@gmail.com> wrote: I noticed that the md5 computed with md5 module from python is different then the md5 sum computed with md5sum utility (on slackware and gentoo).
i.e. $echo marius|md5sum 0f0f60ac801a9eec2163083a22307deb -
test = md5.new("marius") print test.hexdigest() 242aa1a97769109065e3b4df359bcfc9
Any idea why? and how to get the same md5 sum for both calls?
echo adds a newline: import md5 test = md5.new("marius\n") print test.hexdigest()
0f0f60ac801a9eec2163083a22307deb
Just ur************@gmail.com said the following on 07.05.2006 12:07: Hi
I noticed that the md5 computed with md5 module from python is different then the md5 sum computed with md5sum utility (on slackware and gentoo).
i.e. $echo marius|md5sum 0f0f60ac801a9eec2163083a22307deb -
test = md5.new("marius") print test.hexdigest()
242aa1a97769109065e3b4df359bcfc9
Any idea why? and how to get the same md5 sum for both calls?
Thanks
try md5sum marius
probably "new line" character is not computed in "echo marius|md5sum"
--
Dejan Rodiger - PGP ID 0xAC8722DC
Delete wirus from e-mail address
> echo adds a newline: >>> import md5 >>> test = md5.new("marius\n") >>> print test.hexdigest()
0f0f60ac801a9eec2163083a22307deb
Just
Thanks, that was it ;)
"Marius Ursache" <ur************@gmail.com> writes: >>> import md5 >>> test = md5.new("marius\n") >>> print test.hexdigest() 0f0f60ac801a9eec2163083a22307deb
Thanks, that was it ;)
Also, the -n option suppresses the newline from echo:
$ echo -n marius | md5sum
242aa1a97769109065e3b4df359bcfc9 - ur************@gmail.com wrote: Hi
I noticed that the md5 computed with md5 module from python is different then the md5 sum computed with md5sum utility (on slackware and gentoo).
i.e. $echo marius|md5sum 0f0f60ac801a9eec2163083a22307deb -
test = md5.new("marius") print test.hexdigest()
242aa1a97769109065e3b4df359bcfc9
Any idea why? and how to get the same md5 sum for both calls?
Thanks
Just a quick md5-related follow-up question: I was experimenting with it
and making md5 sums for strings, but how do you use the md5 module to
create a sum for an actual file, such as an .exe file?
Thanks.
John Salerno <jo******@NOSPAMgmail.com> writes: Just a quick md5-related follow-up question: I was experimenting with it and making md5 sums for strings, but how do you use the md5 module to create a sum for an actual file, such as an .exe file?
m = md5.new()
f = file('foo.exe', 'b') # open in binary mode
while True:
t = f.read(1024)
if len(t) == 0: break # end of file
m.update(t)
print m.hexdigest()
Paul Rubin wrote: John Salerno <jo******@NOSPAMgmail.com> writes: Just a quick md5-related follow-up question: I was experimenting with it and making md5 sums for strings, but how do you use the md5 module to create a sum for an actual file, such as an .exe file?
m = md5.new() f = file('foo.exe', 'b') # open in binary mode while True: t = f.read(1024) if len(t) == 0: break # end of file m.update(t) print m.hexdigest()
Any reason you can't just read the whole file at once and update m?
Also, doesn't the parameter for update have to be a string? If you're
reading the file in binary mode, would t still be a string?
Thanks.
John Salerno <jo******@NOSPAMgmail.com> writes: Any reason you can't just read the whole file at once and update m?
Yes, you could say
print md5.new(file('foo.exe').read()).hexdigest()
but that means reading the whole file into memory at once. If the
file is very large, that could thrash or fail.
Also, doesn't the parameter for update have to be a string? If you're reading the file in binary mode, would t still be a string?
Yes, t would still be a string. You can have NUL bytes and so forth
in Python strings:
len('ab\0cd') ==> 5
Paul Rubin wrote: John Salerno <jo******@NOSPAMgmail.com> writes: Any reason you can't just read the whole file at once and update m?
Yes, you could say
print md5.new(file('foo.exe').read()).hexdigest()
but that means reading the whole file into memory at once. If the file is very large, that could thrash or fail.
Also, doesn't the parameter for update have to be a string? If you're reading the file in binary mode, would t still be a string?
Yes, t would still be a string. You can have NUL bytes and so forth in Python strings:
len('ab\0cd') ==> 5
Thanks! I didn't expect it to be so easy. :) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: calmar |
last post by:
Hi all,
I would like to use python for a replacement for some binutils. I would
like to be able to pipe things into python. Actually I would not like
writing a 'script' to handle the input, but...
|
by: Xah Lee |
last post by:
http://python.org/doc/2.4.1/lib/module-re.html
http://python.org/doc/2.4.1/lib/node114.html
---------
QUOTE
The module defines several functions, constants, and an exception. Some
of the...
|
by: jtan325 |
last post by:
hi,
i am running Linux Ubuntu Hoary and am trying to build the Python
numarray package, v. 1.3.2 by hand since ubuntu's repos won't be
updated until breezy.
i have python 2.4, and gcc 3.3.5
...
|
by: Paul Cochrane |
last post by:
Hi all,
I've got an application that I'm writing that autogenerates python code
which I then execute with exec(). I know that this is not the best way to
run things, and I'm not 100% sure as to...
|
by: Pierre Rouleau |
last post by:
Hi all,
I have a consistent test case where os.popen3() hangs in Windows. The
system hangs when retrieving the lines from the child process stdout.
I know there were several reports related to...
|
by: Ben Sizer |
last post by:
I've installed several different versions of Python across several
different versions of MS Windows, and not a single time was the Python
directory or the Scripts subdirectory added to the PATH...
|
by: PengYu.UT |
last post by:
Hi,
I feel argparse has some useful things that optparse doesn't have. But
I can't find it argparse in python library reference. I'm wondering
when it will be available in the python standard...
|
by: adamurbas |
last post by:
ya so im pretty much a newb to this whole python thing... its pretty
cool but i just started today and im already having trouble. i
started to use a tutorial that i found somewhere and i followed...
|
by: Yves Dorfsman |
last post by:
On UNIX, some people use
#!/usr/bin/env python
While other use
#!/usr/bin/python
Why is one preferred over the other one ?
Thanks.
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |