| 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
| |||||||||||
| 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__ | ||||||||||