[plt-scheme] MD5 in v299.400

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Fri Oct 21 07:57:06 EDT 2005

David Richards wrote:

>
> I don't understand the discrepancy between the definition of md5 in  
> md5.ss, and the one which is provided by (require (lib "md5.ss")).

Where is the first the first md5.ss located? The one in (require (lib 
"md5.ss")) is in "collects/mzlib/md5.ss".

> I don't understand why md5 requires a byte-string argument, instead  
> of a string.

That is due to unicode. The md5-algorithm works on good, old strings 
consisting
of 8-bit characters. The source of md5.ss keeps mentioning strings, but 
note that
it was written in 2002, before unicode and byte-strings were introduced 
in PLT Scheme.

> The test code in "md5.ss" does not evaluate, because arguments are  
> the wrong type.

The uncommented test is the original one. Here is an updated version:

(define (md5-test)
    (if (and (equal? (md5 #"")
                     #"d41d8cd98f00b204e9800998ecf8427e")
             (equal? (md5 #"a")
                     #"0cc175b9c0f1b6a831c399e269772661")
             (equal? (md5 #"abc")
                     #"900150983cd24fb0d6963f7d28e17f72")
             (equal? (md5 #"message digest")
                     #"f96b697d7cb7938d525a2f31aaf161d0")
             (equal? (md5 #"abcdefghijklmnopqrstuvwxyz")
                     #"c3fcd3d76192e4007dfb496cca67e13b")
             (equal? (md5 
#"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
                     #"d174ab98d277d9f5a5611c2c9f419d9f")
             (equal? (md5 
#"12345678901234567890123456789012345678901234567890123456789012345678901234567890")
                     #"57edf4a22be3c955ac49da2e2107b67a"))
        'passed
        'failed))
 
 > (md5-test)
passed

The PLT test-suite contains the following test:

    <http://pre.plt-scheme.org/plt/collects/tests/mzscheme/md5.ss>

-- 
Jens Axel Søgaard




Posted on the users mailing list.