MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: MD5 Brain teaser

  • To: mathgroup at smc.vnet.net
  • Subject: [mg55491] Re: [mg55484] MD5 Brain teaser
  • From: Igor Antonio <igora at wolf-ram.com>
  • Date: Sat, 26 Mar 2005 02:39:22 -0500 (EST)
  • Organization: Wolfram Research, Inc.
  • References: <200503251048.FAA11370@smc.vnet.net>
  • Reply-to: igora at wolf-ram.com
  • Sender: owner-wri-mathgroup at wolfram.com

Barthelet, Luc wrote:
> I can't find a Mathematica implementation of MD5 checksum anywhere.
> There is one email question in mathgroup in 1998 but no answer.
> 
> Anyone feel like implementing it? I could use it.
> 
> I found this algorithm description that includes a validation of the
> implementation.
> http://www.columbia.edu/~ariel/ssleay/rfc1321.html
> 
> Thanks in advance,
> 
> Luc

Hi Luc,

Brenton Bostick sent me this alternative a while ago and it might work 
for you:

I use Java's MessageDigest class for checksums.

MD5 returns 16 bytes. As long as security isn't an issue, MD5 should be 
fine.

In[1]:=
<<JLink`;

In[2]:=
InstallJava[];

In[3]:=
LoadJavaClass["java.security.MessageDigest"];

In[4]:=
md=MessageDigest`getInstance["MD5"];

In[5]:=
md@digest[JavaNew["java.lang.String","string1"]@getBytes[]]

Out[5]=
{52,-75,119,-66,32,-5,-63,84,119,-86,-37,-102,8,16,31,-7}

In[6]:=
md@digest[JavaNew["java.lang.String","string2"]@getBytes[]]

Out[6]=
{-111,-64,-59,-100,-113,111,-55,-86,45,-55,-102,-119,-14,-3,10,-75}

In[7]:=
long=StringJoin[Table["4",{10^4}]];

In[8]:=
md@digest[JavaNew["java.lang.String",long]@getBytes[]]

Out[8]=
{-33,19,37,92,-51,-62,102,24,39,-87,117,-14,-9,-42,112,110}

In[9]:=
longer=StringJoin[Table["4",{10^6}]];

In[10]:=
md@digest[JavaNew["java.lang.String",longer]@getBytes[]]

Out[10]=
{-115,92,61,-96,11,-55,67,-103,119,-35,-91,-114,112,-104,57,84}

HTH

Igor

-- 


Igor Antonio
Wolfram Research, Inc.
http://www.wolfram.com

To email me personally, remove the dash.


  • Prev by Date: Re: Simple Sum does not simplify
  • Next by Date: NMinimize Strange Results
  • Previous by thread: Re: MD5 Brain teaser
  • Next by thread: Re: MD5 Brain teaser