Md5

Could it be that the results of the MD5-Digest algorithm implemented in
ruby are different from “md5sum”?
If yes, why?
If no, what did I wrong?

[code (ruby)]
dodger@satan:~$ irb
irb(main):001:0> require 'md5’
true
irb(main):002:0> MD5.md5(‘hello’)
5d41402abc4b2a76b9719d911017c592

[shell]
dodger@satan:~$ echo hello > hello
dodger@satan:~$ md5sum hello
b1946ac92492d2347c6235b4d2611184 hello

···


“Die Geschichte wiederholt sich nicht, wohl aber die Leichtfertigkeit,
mit der sie gemacht wird.” [W.Weidner]

You forgot about the newline character that ‘echo’ produces by default.

$ echo -n hello | md5sum
5d41402abc4b2a76b9719d911017c592
$ echo hello | md5sum
b1946ac92492d2347c6235b4d2611184

···

On Wed, 27 Nov 2002 21:47:50 +0100, Sebastian Ruhs wrote:

[code (ruby)]
dodger@satan:~$ irb
irb(main):001:0> require ‘md5’
true
irb(main):002:0> MD5.md5(‘hello’)
5d41402abc4b2a76b9719d911017c592

[shell]
dodger@satan:~$ echo hello > hello
dodger@satan:~$ md5sum hello
b1946ac92492d2347c6235b4d2611184 hello

“Sebastian Ruhs” RembrandtAkaDodger@gmx.de writes:

[code (ruby)]
dodger@satan:~$ irb
irb(main):001:0> require ‘md5’
true
irb(main):002:0> MD5.md5(‘hello’)
5d41402abc4b2a76b9719d911017c592

irb(main):004:0> MD5.md5(“hello\n”)
b1946ac92492d2347c6235b4d2611184

[shell]
dodger@satan:~$ echo hello > hello
dodger@satan:~$ md5sum hello
b1946ac92492d2347c6235b4d2611184 hello

echo adds a newline to the end of the string it’s echoing. Use -n to
omit it:

$ echo -n hello | md5sum
5d41402abc4b2a76b9719d911017c592 -

$ ruby -e ‘require “md5”; puts MD5.md5(“hello”)’
5d41402abc4b2a76b9719d911017c592

···


Josh Huber

“Sebastian Ruhs” RembrandtAkaDodger@gmx.de writes:

Could it be that the results of the MD5-Digest algorithm implemented in
ruby are different from “md5sum”?
If yes, why?
If no, what did I wrong?

[code (ruby)]
dodger@satan:~$ irb
irb(main):001:0> require ‘md5’
true
irb(main):002:0> MD5.md5(‘hello’)
5d41402abc4b2a76b9719d911017c592

[shell]
dodger@satan:~$ echo hello > hello
dodger@satan:~$ md5sum hello
b1946ac92492d2347c6235b4d2611184 hello

hrothgar ~ % echo hello | md5
b1946ac92492d2347c6235b4d2611184
hrothgar ~ % echo -n hello | md5
5d41402abc4b2a76b9719d911017c592

The way you used ‘echo’ put a newline after “hello”, hence the
different hash.

···


Steve Coltrin spcoltri@omcl.org
ALLERGEN INFORMATION: This post is packaged on shared equipment
with peanuts and/or other nut meats.

Yes, you’re right. What a stupid mistake…
Thx!

so long…

···

On Wed, 27 Nov 2002 22:21:12 +0100, Sebastian Kapfer wrote:

On Wed, 27 Nov 2002 21:47:50 +0100, Sebastian Ruhs wrote:

[code (ruby)]
dodger@satan:~$ irb
irb(main):001:0> require ‘md5’
true
irb(main):002:0> MD5.md5(‘hello’)
5d41402abc4b2a76b9719d911017c592

[shell]
dodger@satan:~$ echo hello > hello
dodger@satan:~$ md5sum hello
b1946ac92492d2347c6235b4d2611184 hello

You forgot about the newline character that ‘echo’ produces by default.

$ echo -n hello | md5sum
5d41402abc4b2a76b9719d911017c592
$ echo hello | md5sum
b1946ac92492d2347c6235b4d2611184


“Die Geschichte wiederholt sich nicht, wohl aber die Leichtfertigkeit,
mit der sie gemacht wird.” [W.Weidner]