File: onezeropadding.t

package info (click to toggle)
libcrypt-cbc-perl 2.29-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 180 kB
  • ctags: 48
  • sloc: perl: 1,348; makefile: 42
file content (50 lines) | stat: -rw-r--r-- 1,041 bytes parent folder | download | duplicates (2)
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
#!/usr/local/bin/perl

use lib '..','../blib/lib','.','./blib/lib';

my (@mods,@pads,@in,$tnum);

@mods = qw/Rijndael
           Blowfish
           Blowfish_PP
           IDEA
           DES
          /;

for $mod (@mods) {
   eval "use Crypt::$mod(); 1" && push @in,$mod;
}

unless ($#in > -1) {
   print "1..0 # Skipped: no cryptographic modules found\n";
   exit;
} else {
    print "1..2\n";
}

sub test {
    local($^W) = 0;
    my($num, $true,$msg) = @_;
    $$num++;
    print($true ? "ok $$num\n" : "not ok $$num $msg\n");
}

$tnum = 0;

eval "use Crypt::CBC";
print STDERR "using Crypt\:\:$in[0] for testing\n";
test(\$tnum,!$@,"Couldn't load module");


my $cipher = Crypt::CBC->new(
			     -key    => 'aaab',
			     -cipher => $in[0],
			     -padding => "oneandzeroes",
);
my $string = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAX';

my $work  = $cipher->encrypt($string); #Encrypt string
my $plain = $cipher->decrypt($work); #...and decrypt

test(\$tnum,$string eq $plain,"oneandzeroes padding not working\n");