Oromis92 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl @r = ((7,12,17,22) x 4 , (5,9,14,20) x 4 , (4,11,16,23) x 4 , (6,10,15 +,21) x 4); $k[$_] = (int(abs(sin($_+1))*(2**32))) for 0..63; $H0 = 0x67452301; $H1 = 0xefcdab89; $H2 = 0x98badcfe; $H3 = 0x10325476; print "> "; @msg = map(ord, split // , <>); pop @msg; $msgbin .= 0 . sprintf('%b',$msg[$_]) for 0..$#msg; $length = sprintf('%b',length $msgbin); $length = 0 . $length while length $length < 64; $msgbin .= 1; $msgbin .= 0 until length $msgbin == 448 % 512; $msgbin .= $length; for ($i=0,$j=0;$j<16;$i+=32,$j++) { $w[$j] = (unpack("N", pack("B32", substr("0" x 32 . (substr($msgbin +,$i,32)), -32)))) % (2**32); } $a = $H0; $b = $H1; $c = $H2; $d = $H3; for $i (0..63) { if ($i >= 0 && $i <= 15) { $f = (($b & $c) | ((~$b) & $d)) % (2**32); $g = $i; } elsif ($i >= 16 && $i <= 31) { $f = (($d & $b) | ((~$d) & $c)) % (2**32); $g = (5*$i + 1) % 16; } elsif ($i >= 32 && $i <= 47) { $f = ($b ^ $c ^ $d) % (2**32); $g = (3*$i + 1) % 16; } elsif ($i >= 48 && $i <= 63) { $f = ($c ^ ($b | (~$d))) % (2**32); $g = (7*$i + 1) % 16; } $temp = $d % (2**32); $d = $c % (2**32); $c = $b % (2**32); $b = ($b + (($a + $f + $k[$i] + $w[$g]) << $r[$i])) % (2**32); $a = $temp % (2**32); } $H0 = unpack("H8", pack("N", ($H0 + $a))); $H1 = unpack("H8", pack("N", ($H1 + $b))); $H2 = unpack("H8", pack("N", ($H2 + $c))); $H3 = unpack("H8", pack("N", ($H3 + $d))); $digest = $H0.$H1.$H2.$H3; print "> $digest\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: MD5 -- not digest::md5
by roboticus (Chancellor) on Aug 15, 2009 at 14:09 UTC | |
by JavaFan (Canon) on Aug 15, 2009 at 17:04 UTC | |
by roboticus (Chancellor) on Aug 16, 2009 at 12:58 UTC | |
Re: MD5 -- not digest::md5
by CountZero (Bishop) on Aug 15, 2009 at 14:46 UTC | |
by Oromis92 (Sexton) on Aug 15, 2009 at 15:39 UTC | |
by youlose (Scribe) on Aug 15, 2009 at 16:52 UTC | |
by pKai (Priest) on Aug 15, 2009 at 21:07 UTC | |
Re: MD5 -- not digest::md5
by FunkyMonk (Chancellor) on Aug 15, 2009 at 22:58 UTC | |
Re: MD5 -- not digest::md5
by Anonymous Monk on Aug 15, 2009 at 09:55 UTC | |
by Oromis92 (Sexton) on Aug 15, 2009 at 10:05 UTC | |
by Anonymous Monk on Aug 15, 2009 at 10:52 UTC | |
by ikegami (Patriarch) on Aug 15, 2009 at 15:38 UTC | |
Re: MD5 -- not digest::md5
by locked_user mtve (Deacon) on Aug 16, 2009 at 07:23 UTC | |
Re: MD5 -- not digest::md5
by pKai (Priest) on Aug 16, 2009 at 10:35 UTC |