-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.pl
More file actions
85 lines (65 loc) · 1.94 KB
/
test.pl
File metadata and controls
85 lines (65 loc) · 1.94 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use strict;
use Test;
use vars qw($loaded);
use Benchmark qw(timediff timestr);
BEGIN { plan tests => 6 }
END { print "not ok 1\n" unless $loaded }
my $key = pack "H*", '1234567890ABCDEFFEDCBA0987654321';
my $plaintext = "The quick brown fox jumps over the lazy dog.";
use Crypt::TEA;
ok($loaded = 1);
ok(my $tea = Crypt::TEA->new("abcdefghijklmnop"));
ok("aaaabbbb", $tea->decrypt($tea->encrypt("aaaabbbb")));
eval 'use Crypt::CBC';
if ($@) { print "skipping Crypt::CBC test\n"; }
else {
print "trying CBC... ";
my $c = Crypt::CBC->new($key, "TEA") || die "$!\n";
my $t = $c->encrypt_hex($plaintext);
ok($plaintext, $c->decrypt_hex($t));
}
print "\nBenchmarks\n";
{
my $s = Benchmark->new;
for (my $i = 0; $i < 20000; $i++) {
my $in = pack "H*", "0123456789ABCDEF";
my $c = Crypt::TEA->new($key);
$c->encrypt($in);
}
my $t = Benchmark->new;
print "Encrypting (20,000 cycles, uncached cipher): ",
timestr(timediff($t, $s)), "\n";
}
{
my $s = Benchmark->new;
for (my $i = 0; $i < 20000; $i++) {
my $in = pack "H*", "0123456789ABCDEF";
my $c = Crypt::TEA->new($key);
$c->decrypt($in);
}
my $t = Benchmark->new;
print "Decrypting (20,000 cycles, uncached cipher): ",
timestr(timediff($t, $s)), "\n";
}
{
my $c = Crypt::TEA->new($key);
my $s = Benchmark->new;
for (my $i = 0; $i < 50000; $i++) {
my $in = pack "H*", "0123456789ABCDEF";
$c->encrypt($in);
}
my $t = Benchmark->new;
print "Encrypting (50,000 cycles, cached cipher): ",
timestr(timediff($t, $s)), "\n";
}
{
my $c = Crypt::TEA->new($key);
my $s = Benchmark->new;
for (my $i = 0; $i < 50000; $i++) {
my $in = pack "H*", "0123456789ABCDEF";
$c->decrypt($in);
}
my $t = Benchmark->new;
print "Decrypting (50,000 cycles, cached cipher): ",
timestr(timediff($t, $s)), "\n";
}