[plt-scheme] FFI and MD5

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Wed Jan 31 16:44:03 EST 2007

Matthew Flatt skrev:
> At Wed, 31 Jan 2007 22:21:11 +0100, Jens Axel Søgaard wrote:
>> So the message digest (the md) of #"" is 
>> #"d41d8cd98f00b204e9800998ecf8427e".
> 
> This is a representation of 16 8-bit numbers where each 8-bit number is
> shown as a 2-digit hex number, right? (It's a byte string of length 32.)
> 
>>  > (md5 #"")
>> "Ô\u001D\u008CÙ\u008F\u0000\u00B2\u0004é\u0080\t\u0098ìøB~"
> 
> This is a representation of 16 8-bit numbers where each 8-bit number is
> shown as a Unicode character. (It's a string of length 16.)

Now I get it! Gregory *was* spot on:

   (define (md5 d)
     (let ([md (MD5 d #f)])
       (let loop ([i 0] [cs '()])
         (if (= i 16)
             (apply string-append
                    (map (lambda (c) (number->string c 16))
                         (reverse cs)))
             (loop (+ i 1) (cons (ptr-ref md _byte i) cs))))))

> They encode differently the same result, right?

 > (md5 #"")
"d41d8cd98f0b24e980998ecf8427e"

Yep!

-- 
Jens Axel Søgaard




Posted on the users mailing list.