line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::RandomEncryption; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21665
|
use 5.014002; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
733
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
11
|
0
|
|
|
|
|
|
my $self = bless { @_ }, $class; |
12
|
0
|
|
|
|
|
|
return $self; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _packit |
16
|
|
|
|
|
|
|
{ |
17
|
0
|
|
|
0
|
|
|
shift; |
18
|
0
|
|
|
|
|
|
my $phrase=shift; |
19
|
0
|
|
|
|
|
|
return pack("H*",$phrase); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _unpackit |
23
|
|
|
|
|
|
|
{ |
24
|
0
|
|
|
0
|
|
|
shift; |
25
|
0
|
|
|
|
|
|
my $phrase=shift; |
26
|
0
|
|
|
|
|
|
return unpack("H*",$phrase); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _random |
30
|
|
|
|
|
|
|
{ |
31
|
0
|
|
|
0
|
|
|
shift; |
32
|
0
|
|
|
|
|
|
my @range=('a'..'z', 'A'..'Z', 0..9); |
33
|
0
|
|
|
|
|
|
return $range[rand($#range+1)]; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _RC4 { |
37
|
0
|
|
|
0
|
|
|
shift; |
38
|
0
|
|
|
|
|
|
my($plaintext, $key) = @_; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $keylen = length($key); |
41
|
0
|
|
|
|
|
|
my @keyarray; |
42
|
0
|
|
|
|
|
|
for(my $i=0; $i<=255; $i++) { |
43
|
0
|
|
|
|
|
|
$keyarray[$i]=ord(substr($key,($i % $keylen)+1, 1)); |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
my @asciiarray; |
46
|
0
|
|
|
|
|
|
for(my $i=0; $i<=255; $i++) { |
47
|
0
|
|
|
|
|
|
$asciiarray[$i] = $i; |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
|
|
|
|
my $j=0; |
50
|
0
|
|
|
|
|
|
for(my $i=0; $i<=255; $i++) { |
51
|
0
|
|
|
|
|
|
$j=($j + $asciiarray[$i] + $keyarray[$i]) % 256; |
52
|
0
|
|
|
|
|
|
($asciiarray[$i], $asciiarray[$j])=($asciiarray[$j], $asciiarray[$i]); |
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
|
|
|
|
my $i=0; |
55
|
0
|
|
|
|
|
|
$j=0; |
56
|
0
|
|
|
|
|
|
my $t; |
57
|
|
|
|
|
|
|
my $y; |
58
|
0
|
|
|
|
|
|
my $RC4; |
59
|
0
|
|
|
|
|
|
for (my $x = 0; $x < length($plaintext); $x++) { |
60
|
0
|
|
|
|
|
|
$i=($i + 1) % 256; |
61
|
0
|
|
|
|
|
|
$j=($j + $asciiarray[$i])%256; |
62
|
0
|
|
|
|
|
|
$t = ($asciiarray[$i] + $asciiarray[$j]) % 256; |
63
|
0
|
|
|
|
|
|
($asciiarray[$i], $asciiarray[$j])=($asciiarray[$j], $asciiarray[$i]); |
64
|
0
|
|
|
|
|
|
$y = $asciiarray[$t]; |
65
|
0
|
|
|
|
|
|
$RC4=$RC4 . chr(ord(substr($plaintext, $x, 1))^$y); |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
|
return $RC4; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub encrypt |
71
|
|
|
|
|
|
|
{ |
72
|
0
|
|
|
0
|
1
|
|
my $class=shift; |
73
|
0
|
|
|
|
|
|
my ($item, $key, $level)=@_; |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
unless($level) { $level=1; } |
|
0
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$item=$class->_unpackit($class->_RC4($item, $key)); |
77
|
0
|
|
|
|
|
|
my @items=split(//, $item); |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my @bet; |
80
|
0
|
|
|
|
|
|
for(my $j=0; $j < $level; $j++) { |
81
|
0
|
|
|
|
|
|
for(my $i=0; $i <= $#items; $i++) { |
82
|
0
|
|
|
|
|
|
my $r=$class->_random(); |
83
|
0
|
|
|
|
|
|
push(@bet, ($r, $items[$i])); |
84
|
0
|
0
|
|
|
|
|
if($i == $#items) { |
85
|
0
|
|
|
|
|
|
push(@bet, $r); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
|
|
|
@items=@bet; |
89
|
0
|
|
|
|
|
|
@bet=(); |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
my $bet=join('', @items); |
92
|
0
|
|
|
|
|
|
my $final=$class->_unpackit($class->_RC4($bet, $key)); |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return $final; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub decrypt |
98
|
|
|
|
|
|
|
{ |
99
|
0
|
|
|
0
|
1
|
|
my $class=shift; |
100
|
0
|
|
|
|
|
|
my ($encrypted, $key, $level)=@_; |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
unless($level) { $level=1; } |
|
0
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $first=$class->_RC4($class->_packit($encrypted),$key); |
104
|
0
|
|
|
|
|
|
my @items=split(//, $first); |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my @bet; |
107
|
0
|
|
|
|
|
|
for(my $j=0; $j < $level; $j++) { |
108
|
0
|
|
|
|
|
|
for(my $i=1; $i <= $#items; $i=$i+2) { |
109
|
0
|
|
|
|
|
|
push(@bet, $items[$i]); |
110
|
|
|
|
|
|
|
} |
111
|
0
|
|
|
|
|
|
@items=@bet; |
112
|
0
|
|
|
|
|
|
@bet=(); |
113
|
|
|
|
|
|
|
} |
114
|
0
|
|
|
|
|
|
my $bet=join('', @items); |
115
|
0
|
|
|
|
|
|
my $plain=$class->_RC4($class->_packit($bet),$key); |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
return $plain; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |