line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SSH::Perl::Cipher::RC4; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Net::SSH::Perl::Cipher; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
7
|
1
|
|
|
1
|
|
10
|
use base qw( Net::SSH::Perl::Cipher ); |
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
713
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
11
|
0
|
|
|
|
|
|
my $ciph = bless { }, $class; |
12
|
0
|
0
|
|
|
|
|
$ciph->init(@_) if @_; |
13
|
0
|
|
|
|
|
|
$ciph; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub init { |
17
|
0
|
|
|
0
|
0
|
|
my $ciph = shift; |
18
|
0
|
|
|
|
|
|
my($key, $iv) = @_; |
19
|
0
|
|
|
|
|
|
$ciph->{key} = substr($key, 0, $ciph->keysize); |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
$key = substr($key, 0, $ciph->keysize); |
22
|
0
|
|
|
|
|
|
my @k = unpack 'C*', $key; |
23
|
0
|
|
|
|
|
|
my @s = 0..255; |
24
|
0
|
|
|
|
|
|
my($y) = (0); |
25
|
0
|
|
|
|
|
|
for my $x (0..255) { |
26
|
0
|
|
|
|
|
|
$y = ($k[$x % @k] + $s[$x] + $y) % 256; |
27
|
0
|
|
|
|
|
|
@s[$x, $y] = @s[$y, $x]; |
28
|
|
|
|
|
|
|
} |
29
|
0
|
|
|
|
|
|
$ciph->{s} = \@s; |
30
|
0
|
|
|
|
|
|
$ciph->{x} = 0; |
31
|
0
|
|
|
|
|
|
$ciph->{y} = 0; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
0
|
|
sub blocksize { 8 } |
35
|
0
|
|
|
0
|
0
|
|
sub keysize { 16 } |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub encrypt { |
38
|
0
|
|
|
0
|
1
|
|
my($ciph, $text) = @_; |
39
|
0
|
|
|
|
|
|
$text = RC4($ciph, $text); |
40
|
0
|
|
|
|
|
|
$text; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub decrypt { |
44
|
0
|
|
|
0
|
1
|
|
my($ciph, $text) = @_; |
45
|
0
|
|
|
|
|
|
$text = RC4($ciph, $text); |
46
|
0
|
|
|
|
|
|
$text; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub RC4 { |
50
|
0
|
|
|
0
|
0
|
|
my($ciph, $text) = @_; |
51
|
0
|
|
|
|
|
|
my($x, $y, $trans) = ($ciph->{x}, $ciph->{y}, ''); |
52
|
0
|
|
|
|
|
|
my $s = $ciph->{s}; |
53
|
0
|
|
|
|
|
|
for my $c (unpack 'C*', $text) { |
54
|
0
|
|
|
|
|
|
$x = ($x + 1) % 256; |
55
|
0
|
|
|
|
|
|
$y = ( $s->[$x] + $y ) % 256; |
56
|
0
|
|
|
|
|
|
@$s[$x, $y] = @$s[$y, $x]; |
57
|
0
|
|
|
|
|
|
$trans .= pack('C', $c ^= $s->[( $s->[$x] + $s->[$y] ) % 256]); |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
|
$ciph->{x} = $x; |
60
|
0
|
|
|
|
|
|
$ciph->{y} = $y; |
61
|
0
|
|
|
|
|
|
$trans; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
__END__ |