MD5: Difference between revisions
→{{header|PARI/GP}}: modified example ; simplification & possible bug fix in code
(→{{header|PARI/GP}}: simplifications & examples) |
(→{{header|PARI/GP}}: modified example ; simplification & possible bug fix in code) |
||
Line 2,261:
<lang PARIgp>md5( message ) = { my(
a = 0x67452301, b = 0xefcdab89, c = 0x98badcfe, d = 0x10325476,
s = [ 7, 12, 17, 22; 5, 9, 14, 20; 4, 11, 16, 23; 6, 10, 15, 21 ],
msg = concat( Vec( concat(Vecsmall(message), Vecsmall(128)), (#message + 9) \ 64 * 64 + 56 ),
Vecrev(digits( #message % 2^61 * 8, 256), 8)), \\ little endian !
Line 2,270 ⟶ 2,271:
M = vector( 16, j, fromdigits( Vecrev(msg[ m + j*4 - 4 .. m + j*4 - 1 ]), 2^8 )),
A = a, B = b, C = c, D = d);
for( i = 0 , 63 ,
if( i < 16 ,
, i < 32 ,
, i < 48 ,
,
)
); \\ end for
[a,b,c,d] = ([a,b,c,d] + [A,B,C,D]) % 2^32 ;
); \\ end forstep
Strprintf("%032x",fromdigits(Vecrev(digits(fromdigits([d,c,b,a],2^32),256),16),256))
}</lang>
Then:
Line 2,288 ⟶ 2,287:
%2 = "d41d8cd98f00b204e9800998ecf8427e"
</pre>
<lang PARIgp>gp > md5("The quick brown fox
<pre>
%3 = "4c57070257998981a0c7b7ec003b9d5c"
</pre>
|