blib/lib/Net/SSH/Perl/Cipher/RC4.pm

filter: Statementstmt 26.5% 13 / 49 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 36.3% 4 / 11 Podpod 42.8% 3 / 7 totaltotal 28.9% 20 / 69 SCAR 23.6
CC
4
Cov
25%
new
6.0
init
6.0
RC4
6.0
CRAP 10.6
« blib/lib/Net/SSH/Perl/Proxy.pm ↑ Summary blib/lib/Net/SSH/Perl/Comp.pm »
1 package Net::SSH::Perl::Cipher::RC4;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Net::SSH::Perl::Cipher;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use base qw( Net::SSH::Perl::Cipher );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub new {
10 0 ▶ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
11 0 my $ciph = bless { }, $class;
12 0 ▶ $ciph->init(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
13 0 $ciph;
14 }
15  
16 sub init {
17 0 ▶ my $ciph = shift;
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
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 ▶sub blocksize { 8 }
Subroutine blocksize: not called CC=1 SCAR=6.9
Pod undocumented
35 0 ▶sub keysize { 16 }
Subroutine keysize: not called CC=1 SCAR=6.9
Pod undocumented
36  
37 sub encrypt {
38 0 ▶ my($ciph, $text) = @_;
Subroutine encrypt: not called CC=1 SCAR=6.9
Pod documented
39 0 $text = RC4($ciph, $text);
40 0 $text;
41 }
42  
43 sub decrypt {
44 0 ▶ my($ciph, $text) = @_;
Subroutine decrypt: not called CC=1 SCAR=6.9
Pod documented
45 0 $text = RC4($ciph, $text);
46 0 $text;
47 }
48  
49 sub RC4 {
50 0 ▶ my($ciph, $text) = @_;
Subroutine RC4: not called CC=2 SCAR=17.9
Pod undocumented
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 1;
65 __END__
« blib/lib/Net/SSH/Perl/Proxy.pm ↑ Summary blib/lib/Net/SSH/Perl/Comp.pm »