Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Keep It Simple, Stupid
 
PerlMonks  

Re^2: MD5 -- not digest::md5

by Oromis92 (Sexton)
on Aug 15, 2009 at 15:39 UTC ( #788903=note: print w/ replies, xml ) Need Help??


in reply to Re: MD5 -- not digest::md5
in thread MD5 -- not digest::md5

ok, i followed all your hints...

#!/usr/bin/perl use Digest::MD5 qw(md5 md5_hex md5_base64); use strict; use warnings; use diagnostics; use integer; my @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); my @k; $k[$_] = (int(abs(sin($_+1))*(2**32))) for 0..63; my $H0 = 0x67452301; my $H1 = 0xefcdab89; my $H2 = 0x98badcfe; my $H3 = 0x10325476; # my $H0 = 19088743; # my $H1 = 2300300783; # my $H2 = 267242392; # my $H3 = 124076833; print "> "; my $msg = <>; my @msg = map(ord, split // , $msg); pop @msg; my $msgbin; $msgbin .= 0 . sprintf('%b',$msg[$_]) for 0..$#msg;; my $length = sprintf('%b',length $msgbin); $length = 0 . $length while length $length < 64; $msgbin .= 1; $msgbin .= 0 until length $msgbin == 448 % 512; $msgbin .= $length; my @w; for (my $i=0,my $j=0;$j<16;$i+=32,$j++) { $w[$j] = (unpack("V", pack("B32", substr("0" x 32 . (substr($msgbin +,$i,32)), -32)))) % (2**32); } my $a = $H0; my $b = $H1; my $c = $H2; my $d = $H3; my $f; my $g; for my $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; } my $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("V", ($H0 + $a))); $H1 = unpack("H8", pack("V", ($H1 + $b))); $H2 = unpack("H8", pack("V", ($H2 + $c))); $H3 = unpack("H8", pack("V", ($H3 + $d))); my $digest = md5_hex($msg); print "> $H0$H1$H2$H3\n> $digest\n";
but still doesn't work...


Comment on Re^2: MD5 -- not digest::md5
Download Code
Re^3: MD5 -- not digest::md5
by youlose (Scribe) on Aug 15, 2009 at 16:52 UTC
    my $H0 = 0x67452301; my $H1 = 0xefcdab89; my $H2 = 0x98badcfe; my $H3 = 0x10325476;
    i think error is there, this values must be other. Read http://www.faqs.org/rfcs/rfc1321.html

      From the the code in the RFC you cited:

      context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476;

      These numbers look pretty much identical to the ones in the Perl code in the OP to me.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://788903]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-04-21 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (490 votes), past polls