Crypt-DES
view release on metacpan or search on metacpan
['1002911698100101', '0000000000000000', '1aeac39a61f0a464'],
['7ca110454a1a6e57', '01a1d6d039776742', '690f5b0d9a26939b'],
['0131d9619dc1376e', '5cd54ca83def57da', '7a389d10354bd271'],
['07a1133e4a0b2686', '0248d43806f67172', '868ebb51cab4599a'],
['3849674c2602319e', '51454b582ddf440a', '7178876e01f19b2a'],
['04b915ba43feb5b6', '42fd443059577fa2', 'af37fb421f8c4095'],
['0113b970fd34f2ce', '059b5e0851cf143a', '86a560f10ec6d85b'],
['0170f175468fb5e6', '0756d8e0774761d2', '0cd3da020021dc09'],
['43297fad38e373fe', '762514b829bf486a', 'ea676b2cb7db2b7a'],
['07a7137045da2a16', '3bdd119049372802', 'dfd64a815caf1a0f'],
['04689104c2fd3b2f', '26955f6835af609a', '5c513c9c4886c088'],
['37d06bb516cb7546', '164d5e404f275232', '0a2aeeae3ff4ab77'],
['1f08260d1ac2465e', '6b056e18759f5cca', 'ef1bf03e5dfa575a'],
['584023641aba6176', '004bd6ef09176062', '88bf0db6d70dee56'],
['025816164629b007', '480d39006ee762f2', 'a1f9915541020b56'],
['49793ebc79b3258f', '437540c8698f3cfa', '6fbf1cafcffd0556'],
['4fb05e1515ab73a7', '072d43a077075292', '2f22e49bab7ca1ac'],
['49e95d6d4ca229bf', '02fe55778117f12a', '5a6b612cc26cce4a'],
['018310dc409b26d6', '1d9d5c5018f728c2', '5f4c038ed12b2e41'],
['1c587f1c13924fef', '305532286d6f295a', '63fac0d034d9f793'],
];
my $i = 1;
my $fail = 0;
my $tt = (scalar(@{$testval}) *2);
print "1..$tt\n";
my $t0 = new Benchmark;
foreach my $tst (@{$testval}) {
my ($anot,$bnot) = (0,0);
foreach(@{$tst}) { $_ = pack("H*",$_) }
my $cipher = new Crypt::DES($tst->[0]);
$anot = 1 unless ($cipher->encrypt($tst->[1]) eq $tst->[2]);
if($anot) {
#print "not ";
$fail++;
}
$i++;
$bnot = 1 unless ($cipher->decrypt($tst->[2]) eq $tst->[1]);
if($bnot) {
#print "not ";
$fail++;
}
;
$i++;
}
my $t1 = new Benchmark;
my $suc = $tt - $fail;
my $fp = sprintf("%0.2f",(($tt / $suc) * 100)) unless $suc == 0;
if($suc == 0) { $fp = '0.00' }
my $td0 = timediff($t1,$t0);
my $ts0 = timestr($td0);
print "$tt basic tests ran in $ts0\n";
print "$suc of $tt tests passed ($fp\%)\n";
if($fail > 0) {
print "Not all tests successful. Please attempt to rebuild the package\n";
} else {
print "\nRunning speed tests...\n";
print "\nnon-cached cipher speed test. 5000 encrypt iterations\n";
my $t2 = new Benchmark;
for(1..5000) {
my $cipher = new Crypt::DES(pack("H*",'1c587f1c13924fef'));
$cipher->encrypt(pack("H*",'305532286d6f295a'));
}
my $t3 = new Benchmark;
my $td1 = timediff($t3,$t2);
my $ts1 = timestr($td1);
print "$ts1\nok 343\n";
print "\nnon-cached cipher speed test. 5000 decrypt iterations\n";
my $t4 = new Benchmark;
for(1..5000) {
my $cipher = new Crypt::DES(pack("H*",'1c587f1c13924fef'));
$cipher->decrypt(pack("H*",'63fac0d034d9f793'));
}
my $t5 = new Benchmark;
my $td2 = timediff($t5,$t4);
my $ts2 = timestr($td2);
print "$ts2\nok 344\n";
print "\ncached cipher speed test. 10000 encrypt iterations\n";
{
my $t6 = new Benchmark;
my $cipher = new Crypt::DES(pack("H*",'1c587f1c13924fef'));
for(1..10000) {
$cipher->encrypt(pack("H*",'305532286d6f295a'));
}
my $t7 = new Benchmark;
my $td3 = timediff($t7,$t6);
my $ts3 = timestr($td3);
print "$ts3\nok 345\n";
}
print "\ncached cipher speed test. 10000 decrypt iterations\n";
{
my $t8 = new Benchmark;
my $cipher = new Crypt::DES(pack("H*",'1c587f1c13924fef'));
for(1..10000) {
$cipher->decrypt(pack("H*",'63fac0d034d9f793'));
}
my $t9 = new Benchmark;
my $td4 = timediff($t9,$t8);
my $ts4 = timestr($td4);
print "$ts4\nok 346\n";
}
}
print "\nTesting Cipher Block Chaining..\n";
eval 'use Crypt::CBC';
if(!$@) {
if($Crypt::CBC::VERSION < 1.22) {
$@ = "CBC mode requires Crypt::CBC version 1.22 or higher.";
} else {
my $cipher = new Crypt::CBC(pack("H*","0123456789ABCDEF"),"DES");
my $ciphertext = $cipher->encrypt(pack("H*","37363534333231204E6F77206973207468652074696D6520666F722000"));
my $plaintext = $cipher->decrypt($ciphertext);
if($plaintext ne "7654321 Now is the time for \0") { print "not "; }
print "ok 347 - CBC Mode\n";
}
} # end no errors
if($@) {
print "Error (probably harmless):\n$@\n";
}
print "\nFinished with tests\n\n";
( run in 0.401 second using v1.01-cache-2.11-cpan-96521ef73a4 )