line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=pod
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Crypt::Mimetic::CipherSaber - CipherSaber Encryption Algorithm
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This module is a part of I.
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
This modules uses CipherSaber to encrypt blocks of bytes, so I needs @info containing generic-blocks-length and last-block-length (padlen) to know how decrypt a file. I and I always encrypt/decrypt a string as a single block.
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package Crypt::Mimetic::CipherSaber;
|
17
|
1
|
|
|
1
|
|
6
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
115
|
|
18
|
1
|
|
|
1
|
|
6
|
use Error::Mimetic;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
19
|
1
|
|
|
1
|
|
61
|
use vars qw($VERSION);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1108
|
|
20
|
|
|
|
|
|
|
$VERSION = '0.01';
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
473
|
eval 'use Crypt::CipherSaber';
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
die ("Crypt::CipherSaber required by ". __PACKAGE__) if $@;
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=pod
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 PROCEDURAL INTERFACE
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=item string I ()
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Return a short description of algorithm
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub ShortDescr {
|
36
|
0
|
|
|
0
|
|
|
return "CipherSaber - CipherSaber encryption algorithm.";
|
37
|
|
|
|
|
|
|
}
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=pod
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item boolean I ()
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Return true if password is needed by this algorithm, false otherwise.
|
44
|
|
|
|
|
|
|
('CipherSaber' return always true)
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub PasswdNeeded {
|
49
|
0
|
|
|
0
|
|
|
return 1;
|
50
|
|
|
|
|
|
|
}
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=pod
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item ($len,$blocklen,$padlen,[string]) I ($filename,$output,$algorithm,$key,@info)
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Encrypt a file with CipherSaber algorithm. See I.
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub EncryptFile {
|
61
|
0
|
|
|
0
|
|
|
my ($filename,$output,$algorithm,$key,@info) = @_;
|
62
|
0
|
|
|
|
|
|
my ($buf, $text, $txt) = ("","","");
|
63
|
0
|
|
|
|
|
|
my ($len,$blocklen,$padlen) = (0,0,0);
|
64
|
0
|
0
|
|
|
|
|
if ($output) {
|
65
|
0
|
0
|
|
|
|
|
open(OUT,">>$output") or throw Error::Mimetic "Cannot open $output: $!";
|
66
|
|
|
|
|
|
|
}
|
67
|
0
|
0
|
|
|
|
|
open(IN,"$filename") or throw Error::Mimetic "Cannot open $filename: $!";
|
68
|
0
|
0
|
0
|
|
|
|
$key = Crypt::Mimetic::GetConfirmedPasswd() or throw Error::Mimetic "Password is needed" unless $key;
|
69
|
0
|
|
|
|
|
|
my $cs = new Crypt::CipherSaber($key);
|
70
|
0
|
|
|
|
|
|
while ( read(IN,$buf,32768) ) {
|
71
|
0
|
|
|
|
|
|
$blocklen = $padlen;
|
72
|
0
|
|
|
|
|
|
$text = $cs->encrypt($buf);
|
73
|
0
|
|
|
|
|
|
$padlen = length($text);
|
74
|
0
|
|
|
|
|
|
$len += $padlen;
|
75
|
0
|
0
|
|
|
|
|
if ($output) {
|
76
|
0
|
|
|
|
|
|
print OUT $text;
|
77
|
|
|
|
|
|
|
} else {
|
78
|
0
|
|
|
|
|
|
$txt .= $text;
|
79
|
|
|
|
|
|
|
}
|
80
|
|
|
|
|
|
|
}
|
81
|
0
|
|
|
|
|
|
close(IN);
|
82
|
0
|
0
|
|
|
|
|
if ($output) {
|
83
|
0
|
|
|
|
|
|
close(OUT);
|
84
|
0
|
|
|
|
|
|
return ($len,$blocklen,$padlen);
|
85
|
|
|
|
|
|
|
}
|
86
|
0
|
|
|
|
|
|
return ($len,$blocklen,$padlen,$txt);
|
87
|
|
|
|
|
|
|
}
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=pod
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item string I ($string,$algorithm,$key,@info)
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Encrypt a string with CipherSaber algorithm. See I.
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub EncryptString {
|
98
|
0
|
|
|
0
|
|
|
my ($string,$algorithm,$key,@info) = @_;
|
99
|
0
|
0
|
0
|
|
|
|
$key = Crypt::Mimetic::GetConfirmedPasswd() or throw Error::Mimetic "Password is needed" unless $key;
|
100
|
0
|
|
|
|
|
|
my $cs = new Crypt::CipherSaber($key);
|
101
|
0
|
|
|
|
|
|
return $cs->encrypt($string);
|
102
|
|
|
|
|
|
|
}
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=pod
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item [string] I ($filename,$output,$offset,$len,$algorithm,$key,@info)
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Decrypt a file with CipherSaber algorithm. See I.
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub DecryptFile {
|
113
|
0
|
|
|
0
|
|
|
my ($filename,$output,$offset,$len,$algorithm,$key,@info) = @_;
|
114
|
0
|
|
|
|
|
|
my ($blocklen,$padlen) = @info;
|
115
|
0
|
|
|
|
|
|
my ($buf, $text, $i, $txt) = ("","",0,"");
|
116
|
0
|
|
|
|
|
|
my $blocks = 0;
|
117
|
0
|
0
|
|
|
|
|
$blocks = int($len/$blocklen) if $blocklen;
|
118
|
0
|
0
|
|
|
|
|
if ($output) {
|
119
|
0
|
0
|
|
|
|
|
open(OUT,">$output") or throw Error::Mimetic "Cannot open $output: $!";
|
120
|
|
|
|
|
|
|
}
|
121
|
0
|
0
|
|
|
|
|
open(IN,"$filename") or throw Error::Mimetic "Cannot open $filename: $!";
|
122
|
0
|
0
|
0
|
|
|
|
$key = Crypt::Mimetic::GetPasswd() or throw Error::Mimetic "Password is needed" unless $key;
|
123
|
0
|
|
|
|
|
|
my $cs = new Crypt::CipherSaber($key);
|
124
|
0
|
|
|
|
|
|
seek IN, $offset, 0;
|
125
|
0
|
|
|
|
|
|
for ($i = 0; $i < $blocks; $i++ ) {
|
126
|
0
|
|
|
|
|
|
read(IN,$buf,$blocklen);
|
127
|
0
|
|
|
|
|
|
$text = $cs->decrypt($buf);
|
128
|
0
|
0
|
|
|
|
|
if ($output) {
|
129
|
0
|
|
|
|
|
|
print OUT $text;
|
130
|
|
|
|
|
|
|
} else {
|
131
|
0
|
|
|
|
|
|
$txt .= $text;
|
132
|
|
|
|
|
|
|
}
|
133
|
|
|
|
|
|
|
}
|
134
|
0
|
|
|
|
|
|
read(IN,$buf,$padlen);
|
135
|
0
|
|
|
|
|
|
$text = $cs->decrypt($buf);
|
136
|
0
|
0
|
|
|
|
|
if ($output) {
|
137
|
0
|
|
|
|
|
|
print OUT $text;
|
138
|
|
|
|
|
|
|
} else {
|
139
|
0
|
|
|
|
|
|
$txt .= $text;
|
140
|
|
|
|
|
|
|
}
|
141
|
0
|
|
|
|
|
|
close(IN);
|
142
|
0
|
0
|
|
|
|
|
if ($output) {
|
143
|
0
|
|
|
|
|
|
close(OUT);
|
144
|
|
|
|
|
|
|
} else {
|
145
|
0
|
|
|
|
|
|
return $txt;
|
146
|
|
|
|
|
|
|
}
|
147
|
|
|
|
|
|
|
}
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=pod
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item string I ($string,$algorithm,$key,@info)
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Decrypt a string with CipherSaber algorithm. See I.
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub DecryptString {
|
158
|
0
|
|
|
0
|
|
|
my ($string,$algorithm,$key,@info) = @_;
|
159
|
0
|
0
|
0
|
|
|
|
$key = GetPasswd() or throw Error::Mimetic "Password is needed" unless $key;
|
160
|
0
|
|
|
|
|
|
my $cs = new Crypt::CipherSaber($key);
|
161
|
0
|
|
|
|
|
|
return $cs->decrypt($string);
|
162
|
|
|
|
|
|
|
}
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1;
|
165
|
|
|
|
|
|
|
__END__
|