Calculate the md5 hash of a string

J

Jim Freeze

Hi.

How can I calculate the md5 hash of a string (like in PHP -
http://de2.php.net/manual/en/function.md5.php)? I can't find any
helpfull documentation about this problem.

require 'md5'
MD5.md5("fred") #=> 570a90bfbf8c7eab5dc5d4e26832d5b1


--
Jim Freeze

The birds are singing, the flowers are budding, and it is time for Miss
Manners to tell young lovers to stop necking in public.

It's not that Miss Manners is immune to romance. Miss Manners has been
known to squeeze a gentleman's arm while being helped over a curb, and,
in her wild youth, even to press a dainty slipper against a foot or two
under the dinner table. Miss Manners also believes that the sight of
people strolling hand in hand or arm in arm or arm in hand dresses up a
city considerably more than the more familiar sight of people shaking
umbrellas at one another. What Miss Manners objects to is the kind of
activity that frightens the horses on the street ...
 
W

Wesley J Landaker

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi.

How can I calculate the md5 hash of a string (like in PHP -
http://de2.php.net/manual/en/function.md5.php)? I can't find any
helpfull documentation about this problem.

irb(main):001:0> require 'md5'
=> true
irb(main):002:0> MD5.digest("test")
=> "\t\217k\315F!\323s\312\336N\203&'\264\366"
irb(main):003:0> MD5.hexdigest("test")
=> "098f6bcd4621d373cade4e832627b4f6"
irb(main):004:0> md5 = MD5.new
=> d41d8cd98f00b204e9800998ecf8427e
irb(main):005:0> md5.update("te")
=> 569ef72642be0fadd711d6a468d68ee1
irb(main):006:0> md5 << "st"
=> 098f6bcd4621d373cade4e832627b4f6

- --
Wesley J. Landaker <[email protected]>
OpenPGP FP: 4135 2A3B 4726 ACC5 9094 0097 F0A9 8A4C 4CD6 E3D2

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAP44G8KmKTEzW49IRAuXQAJ9A2cJlP792NzyFoZQmfrSxADo6JACfUSQs
wZuJmemQeeQNmBZ4bHatFis=
=12Hu
-----END PGP SIGNATURE-----
 
G

Gavin Sinclair

Actually I did just that to be able to guess how to calculate the hash and
it's certainly *much* better than no documentation at all, but it's not
what I'd call 'real' documentation for the module.

There's ruby/ext/digest/digest.txt in the source distribution, which
I'll fold into the source code one day, whereupon it will appear in
the the above-linked documentation.

Cheers,
Gavin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top