~ubuntu-branches/ubuntu/maverick/ciphersaber/maverick

« back to all changes in this revision

Viewing changes to t/fh_encrypt.t

  • Committer: Bazaar Package Importer
  • Author(s): Jerome Marant
  • Date: 2002-03-27 07:23:42 UTC
  • Revision ID: james.westby@ubuntu.com-20020327072342-zcvplihmsszct2ok
Tags: upstream-0.60
ImportĀ upstreamĀ versionĀ 0.60

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# tests the fh_encrypt() method
 
2
# this will fail if the state array is not reinitialized ... oops!
 
3
use Crypt::CipherSaber;
 
4
use File::Spec;
 
5
 
 
6
my $crypt_in = File::Spec->catfile('t', 'smiles.cs1');
 
7
my $crypt_out = File::Spec->catfile('t', 'outsmiles.cs1');
 
8
my $img_in = File::Spec->catfile('t', 'smiles.png');
 
9
my $img_out = File::Spec->catfile('t', 'outsmiles.png');
 
10
 
 
11
print "1..4\n";
 
12
 
 
13
open(IN, $crypt_in) or die "Can't get IV!\n";
 
14
binmode(IN);
 
15
my $iv = unpack("a10", <IN>);
 
16
 
 
17
# encrypt a message
 
18
my $cs = Crypt::CipherSaber->new('sdrawkcabsihtdaeR');
 
19
open(IN, $img_in) or die "Can't open input file!\n";
 
20
open(OUT, '>'. $crypt_out) or die "Can't open output file!\n";
 
21
binmode(IN);
 
22
binmode(OUT);
 
23
 
 
24
if ($cs->fh_crypt(\*IN, \*OUT, $iv)) {
 
25
        print "ok 1\n";
 
26
} else {
 
27
        print "not ok 1\n";
 
28
}
 
29
 
 
30
open(ENCRYPTED, $crypt_out) or die "Can't open encrypted file!\n";
 
31
open(FIXED, $crypt_in) or die "Can't open fixed file!\n";
 
32
binmode(ENCRYPTED);
 
33
binmode(FIXED);
 
34
 
 
35
my $status = 0;
 
36
while (<ENCRYPTED>) {
 
37
        my $fixed = <FIXED>;
 
38
        my $pos = 0;
 
39
        for my $char (split(//, $_)) {
 
40
                next if (substr($fixed, $pos++, 1) eq $char);
 
41
                $status = 1;
 
42
        }
 
43
        last if $status;
 
44
}
 
45
 
 
46
if ($status == 0) {
 
47
        print "ok 2\n";
 
48
} else {
 
49
        print "not ok 2\n";
 
50
}
 
51
 
 
52
open(IN, $crypt_in) or die "Can't open input file 2!\n";
 
53
open(OUT, '>' . $img_out) or die "Can't open output file 2!\n";
 
54
binmode(IN);
 
55
binmode(OUT);
 
56
 
 
57
if ($cs->fh_crypt(\*IN, \*OUT)) {
 
58
        print "ok 3\n";
 
59
} else {
 
60
        print "not ok 3\n";
 
61
}
 
62
 
 
63
close(IN);
 
64
close(OUT);
 
65
 
 
66
open(ENCRYPTED, $img_out) or die "Can't open encrypted file!\n";
 
67
open(FIXED, $img_in) or die "Can't open fixed file!\n";
 
68
binmode(ENCRYPTED);
 
69
binmode(FIXED);
 
70
 
 
71
$status = 0;
 
72
while (<ENCRYPTED>) {
 
73
        my $fixed = <FIXED>;
 
74
        my $pos = 0;
 
75
        for my $char (split(//, $_)) {
 
76
                next if (substr($fixed, $pos++, 1) eq $char);
 
77
                $status = 1;
 
78
                print STDERR "Error at line $.\n";
 
79
                last;
 
80
        }
 
81
        last if $status;
 
82
}
 
83
 
 
84
close(ENCRYPTED);
 
85
close(FIXED);
 
86
 
 
87
if ($status == 0) {
 
88
        print "ok 4\n";
 
89
} else {
 
90
        print "not ok 4\n";
 
91
}