NB. RSA Data Security, Inc. MD5 Message-Digest Algorithm NB. See RFC 1321 for license details NB. J implementation -- (C) 2003 Oleg Kobchenko; NB. GNU license; NO WARRANTY FOR ANYTHING require 'convert' coclass 'crypt' NB. lt= (*. -.)~ gt= *. -. ge= +. -. xor= ~: '`lt gt ge xor'=: (20 b.)`(18 b.)`(27 b.)`(22 b.) '`and or rot sh'=: (17 b.)`(23 b.)`(32 b.)`(33 b.) add=: (+&(_16&sh) (16&sh@(+ _16&sh) or and&65535@]) +&(and&65535))"0 hexlist=: tolower@:,@:hfd@:,@:(|."1)@(256 256 256 256&#:) cmn=: 4 : 0 'x s t'=: x. [ 'q a b'=: y. b add s rot (a add q) add (x add t) ) ff=: cmn (((1&{ and 2&{) or 1&{ lt 3&{) , 2&{.) gg=: cmn (((1&{ and 3&{) or 2&{ gt 3&{) , 2&{.) hh=: cmn (((1&{ xor 2&{)xor 3&{ ) , 2&{.) ii=: cmn (( 2&{ xor 1&{ ge 3&{ ) , 2&{.) op=: ff`gg`hh`ii I=: ".;._2(0 : 0) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 6 11 0 5 10 15 4 9 14 3 8 13 2 7 12 5 8 11 14 1 4 7 10 13 0 3 6 9 12 15 2 0 7 14 5 12 3 10 1 8 15 6 13 4 11 2 9 ) S=: 4 4$7 12 17 22 5 9 14 20 4 11 16 23 6 10 15 21 T=: |:".;._2(0 : 0) _680876936 _165796510 _378558 _198630844 _389564586 _1069501632 _2022574463 1126891415 606105819 643717713 1839030562 _1416354905 _1044525330 _373897302 _35309556 _57434055 _176418897 _701558691 _1530992060 1700485571 1200080426 38016083 1272893353 _1894986606 _1473231341 _660478335 _155497632 _1051523 _45705983 _405537848 _1094730640 _2054922799 1770035416 568446438 681279174 1873313359 _1958414417 _1019803690 _358537222 _30611744 _42063 _187363961 _722521979 _1560198380 _1990404162 1163531501 76029189 1309151649 1804603682 _1444681467 _640364487 _145523070 _40341101 _51403784 _421815835 _1120210379 _1502002290 1735328473 530742520 718787259 1236535329 _1926607734 _995338651 _343485551 ) norm=: 3 : 0 n=. 16 * 1 + _6 sh 8 + #y. b=. n#0 [ y=. a.i.y. for_i. i. #y. do. b=. ((j { b) or (8*4|i) sh i{y) (j=. _2 sh i) } b end. b=. ((j { b) or (8*4|i) sh 128) (j=._2 sh i=.#y.) } b _16]\ (8 * #y.) (n-2) } b ) md5=: 3 : 0 X=. norm y. q=. r=. 1732584193 _271733879 _1732584194 271733878 for_x. X do. for_j. i.4 do. l=. ((j{I){x) ,. (16$j{S) ,. j{T for_i. i.16 do. r=. _1|.((i{l) (op@.j) r),}.r end. end. q=. r=. r add q end. hexlist r ) 0 : 0 NB. tests suite (>,. '='"_,. md5_crypt_&>@]) '';'a';'abc';'message digest' =d41d8cd98f00b204e9800998ecf8427e a =0cc175b9c0f1b6a831c399e269772661 abc =900150983cd24fb0d6963f7d28e17f72 message digest=f96b697d7cb7938d525a2f31aaf161d0 (,:md5_crypt_) (i.26)&+&.(a.&i.)'a' abcdefghijklmnopqrstuvwxyz c3fcd3d76192e4007dfb496cca67e13b (,:md5_crypt_) a.{~(a.i.'Aa0');@:(<@(+i.)"0) 26 26 10 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 d174ab98d277d9f5a5611c2c9f419d9f (,:md5_crypt_) 80$'1234567890' 12345678901234567890123456789012345678901234567890123456789012345678901234567890 57edf4a22be3c955ac49da2e2107b67a )