1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#!/usr/bin/perl -w
# $Id$
# Compare results from Digest::Perl::MD5 with Digest::MD5
# Press Ctrl-C to stop the test (on Unix)
# Move Mouse to upper left corner to stop the test (on Windows - you need Win32::API)
# prints 'ok' for every correct MD5 calculation and dies
# if the results are different
use strict;
use lib qw'./lib ../lib';
use Digest::Perl::MD5;
use Digest::MD5;
*pmd5 = \&Digest::Perl::MD5::md5_hex;
*xmd5 = \&Digest::MD5::md5_hex;
my ($count,$bytes) = 0;
my $mult = 10;
sub result { print "\n$count rounds\n$bytes Bytes\n"; exit; };
my $GetCursorPos;
if ($^O eq 'MSWin32') {
eval { require Win32::API; $GetCursorPos = new Win32::API("user32", "GetCursorPos", ['P'], 'V') };
} else {
$SIG{INT} = \&result;
}
$|++;
while(1) {
my $s = gen();
my ($p,$x) = (pmd5($s),xmd5($s));
if ($p ne $x) {
print "\nFailure\n",
'Source: ',unpack('H*',$s),"\n",
"pmd5 : $p\n",
"xmd5 : $x\n";
exit;
} else {
print "ok ";
}
$count++; $bytes+=length $s;
if (defined $GetCursorPos) {
my $lpPoint = pack "LL", 0, 0;
$GetCursorPos->Call($lpPoint);
result() if $lpPoint eq "\0\0\0\0\0\0\0\0";
}
}
sub gen {
my $x;
for (1 .. 1 + rand($count*$mult)) {
$x .= pack 'C', rand 256;
}
$x;
}
|