tags:

views:

705

answers:

1

Does anybody know of ruby implementation of RSA Data Security, Inc. MD5 Message-Digest Algorithm defined at http://tools.ietf.org/html/rfc1321

I found a javascript implementation at https://developer.openx.org/fisheye/browse/openads/branches/2.0/branches/openads-2.0.11/admin/md5.js?r=16584 ... It has a function MD5 which does the encoding. Anything similar on ruby?

+4  A: 

There's plenty of them here

In fact, you're likely to find one using:

require 'digest/md5'
Alnitak
I checked it out, it doesn't seem to have this particular algorithm.
Sanjay
It very likely _does_ have the bog-standard MD5 algorithm. What do you mean?
Alnitak
The algorithm is below (pasted from javascript code) function MD5(entree) ... for (i=0;i<4;i++) ka+=shl(digestBits[15-i], (i*8)); for (i=4;i<8;i++) kb+=shl(digestBits[15-i], ((i-4)*8)); ...s=hexa(kd)+hexa(kc)+hexa(kb)+hexa(ka); return s; digest/md5 does only md5 encoding. This is more complex.
Sanjay
That extra stuff you've found is just hex-encoding the 128-bit result of the MD5 digest. The real MD5 algorithm is found in the stuff I posted.
Alnitak
and BTW, that code at openx.org is broken - it's only good for 7-bit ASCII, so if your text contains byte values < 32 || > 127 it'll produce non-conformant digests.
Alnitak