Crypt-DES_PP

 view release on metacpan or  search on metacpan

test-xs  view on Meta::CPAN

    }
    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_PP(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_PP(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_PP(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 "\ncached cipher speed test.  10000 decrypt iterations\n";
    {
    my $t8 = new Benchmark;
    my $key = pack ("H*", '1c587f1c13924fef');
    my $ciphertext = pack("H*",'63fac0d034d9f793');
    my $cipher = new Crypt::DES_PP($key);
    for(1..10000) {
        $cipher->decrypt($ciphertext);
    }
    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_PP");
                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.776 second using v1.01-cache-2.11-cpan-df04353d9ac )