blib/lib/Crypt/GOST_PP.pm

filter: Statementstmt 100% 53 / 53 Branchbran 100% 10 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 8 totaltotal 86.3% 76 / 88 CC 7 SCAR 7.5
CC
7
Cov
97%
GOST
4.0
Setup
3.0
new
2.0
CRAP 2.1
↑ Summary
1 #--------------------------------------------------------------------#
2 # Crypt::GOST_PP
3 # Date Written: 10-Dec-2001 12:33:55 PM
4 # Last Modified: 26-Feb-2002 10:47:28 AM
5 # Author: Kurt Kincaid (sifukurt@yahoo.com)
6 # Copyright (c) 2002, Kurt Kincaid
7 # All Rights Reserved.
8 #
9 # This is free software and may be modified and/or
10 # redistributed under the same terms as Perl itself.
11 #--------------------------------------------------------------------#
12  
13 package Crypt::GOST_PP;
14 1 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 require Exporter;
16  
17 1 @ISA = qw(Exporter);
18 1 @EXPORT_OK = qw();
19  
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶use vars qw( @b @t @R @S @h @o @K $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 $VERSION = "1.10";
26  
27 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
28 2 my ( $argument, $pp ) = @_;
29 2 Setup( $pp );
30 2 ▶ my $class = ref ( $argument ) || $argument;
Condition33%1/3
ref $argument || $argument
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $argument || $argument
ref $argument $argument
Truth table33%1/3
A || B
A= ref $argumentB= $argument
ABresult
1X1
011
000
31 2 my $self = {};
32 2 bless $self, $class;
33 2 return $self;
34 }
35  
36 1 ▶sub encrypt {
Subroutine encrypt: called CC=1 SCAR=0.0
Pod undocumented
37 1 my ( $self, $text ) = @_;
38 1 return GOST( $text );
39 }
40  
41 1 ▶sub decrypt {
Subroutine decrypt: called CC=1 SCAR=0.0
Pod undocumented
42 1 my ( $self, $text ) = @_;
43 1 return GOST( $text, 1 );
44 }
45  
46 2 ▶sub GOST {
Subroutine GOST: called CC=4 SCAR=13.9
Pod undocumented
47 2 my ( $v, $w, $a, $q, $c, $out, $self );
48 2 my ( $e, $d ) = @_;
49 2 @h = 0 .. 7;
50 2 @o = reverse @h;
51 2 ▶ while ( $a < length $e ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a < length $e) 12 2 14
52 12 $v = N( $e, $a );
53 12 $w = N( $e, ( $a += 8 ) - 4 );
54 12 ▶ grep $q++ % 2 ? $v ^= F( $w + $K[ $_ ] ) : ( $w ^= F( $v + $K[ $_ ] ) ), $d ? ( @h, ( @o ) x 3 ) : ( ( @h ) x 3, @o );
Branch: 2 branches
BranchTrueFalseTotal
$q++ % 2 ? : 192 192 384
$d ? : 6 6 12
55 12 $out .= pack "N2", $w, $v;
56 }
57 2 return $out;
58 }
59  
60 384 ▶sub F {
Subroutine F: called CC=1 SCAR=0.0
Pod undocumented
61 384 my $u = 0;
62 384 grep $u |= $S[ $_ ][ $_[ 0 ] >> $_ * 4 & 15 ] << $_ * 4, reverse 0 .. 7;
63 384 return $u << 11 | $u >> 21;
64 }
65  
66 272 ▶sub R {
Subroutine R: called CC=1 SCAR=0.0
Pod undocumented
67 272 return int( rand( shift ) );
68 }
69  
70 30 ▶sub N {
Subroutine N: called CC=1 SCAR=0.0
Pod undocumented
71 30 return vec $_[ 0 ], $_[ 1 ] / 4, 32;
72 }
73  
74 2 ▶sub Setup {
Subroutine Setup: called CC=3 SCAR=11.0
Pod undocumented
75 2 my $p = shift;
76 2 my ( $s, $i, $c );
77 2 ▶ for ( $i = 0; $i < length $p; $i += 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $p) 6 2 8
78 6 srand( $s ^= N( $p, $i ) );
79 }
80 2 @b = @t = 0 .. 15;
81 2 ▶ while ( $c < 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c < 8) 16 2 18
82 16 grep { push @b, splice @b, R( 9 ), 5 } @t;
83 16 $R[ $c ] = R( 2**32 );
84 16 @{ $S[ $c++ ] } = @b;
85 }
86  
87 }
88  
89 1 1;
90 __END__
↑ Summary