line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
1
|
|
16279
|
use integer; |
|
1
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
5321
|
|
15
|
|
|
|
|
|
|
require Exporter; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
18
|
|
|
|
|
|
|
@EXPORT_OK = qw(); |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
111
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
21
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
30
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
6
|
use vars qw( @b @t @R @S @h @o @K $VERSION ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1363
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$VERSION = "1.10"; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
28
|
2
|
|
|
2
|
0
|
114
|
my ( $argument, $pp ) = @_; |
29
|
2
|
|
|
|
|
11
|
Setup( $pp ); |
30
|
2
|
|
33
|
|
|
30
|
my $class = ref ( $argument ) || $argument; |
31
|
2
|
|
|
|
|
4
|
my $self = {}; |
32
|
2
|
|
|
|
|
7
|
bless $self, $class; |
33
|
2
|
|
|
|
|
7
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub encrypt { |
37
|
1
|
|
|
1
|
0
|
6
|
my ( $self, $text ) = @_; |
38
|
1
|
|
|
|
|
11
|
return GOST( $text ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub decrypt { |
42
|
1
|
|
|
1
|
0
|
7
|
my ( $self, $text ) = @_; |
43
|
1
|
|
|
|
|
4
|
return GOST( $text, 1 ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub GOST { |
47
|
2
|
|
|
2
|
0
|
3
|
my ( $v, $w, $a, $q, $c, $out, $self ); |
48
|
2
|
|
|
|
|
5
|
my ( $e, $d ) = @_; |
49
|
2
|
|
|
|
|
7
|
@h = 0 .. 7; |
50
|
2
|
|
|
|
|
14
|
@o = reverse @h; |
51
|
2
|
|
|
|
|
10
|
while ( $a < length $e ) { |
52
|
12
|
|
|
|
|
20
|
$v = N( $e, $a ); |
53
|
12
|
|
|
|
|
22
|
$w = N( $e, ( $a += 8 ) - 4 ); |
54
|
12
|
100
|
|
|
|
71
|
grep $q++ % 2 ? $v ^= F( $w + $K[ $_ ] ) : ( $w ^= F( $v + $K[ $_ ] ) ), $d ? ( @h, ( @o ) x 3 ) : ( ( @h ) x 3, @o ); |
|
|
100
|
|
|
|
|
|
55
|
12
|
|
|
|
|
46
|
$out .= pack "N2", $w, $v; |
56
|
|
|
|
|
|
|
} |
57
|
2
|
|
|
|
|
13
|
return $out; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub F { |
61
|
384
|
|
|
384
|
0
|
355
|
my $u = 0; |
62
|
384
|
|
|
|
|
1944
|
grep $u |= $S[ $_ ][ $_[ 0 ] >> $_ * 4 & 15 ] << $_ * 4, reverse 0 .. 7; |
63
|
384
|
|
|
|
|
1089
|
return $u << 11 | $u >> 21; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub R { |
67
|
272
|
|
|
272
|
0
|
581
|
return int( rand( shift ) ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub N { |
71
|
30
|
|
|
30
|
0
|
72
|
return vec $_[ 0 ], $_[ 1 ] / 4, 32; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub Setup { |
75
|
2
|
|
|
2
|
0
|
3
|
my $p = shift; |
76
|
2
|
|
|
|
|
3
|
my ( $s, $i, $c ); |
77
|
2
|
|
|
|
|
9
|
for ( $i = 0; $i < length $p; $i += 4 ) { |
78
|
6
|
|
|
|
|
18
|
srand( $s ^= N( $p, $i ) ); |
79
|
|
|
|
|
|
|
} |
80
|
2
|
|
|
|
|
14
|
@b = @t = 0 .. 15; |
81
|
2
|
|
|
|
|
7
|
while ( $c < 8 ) { |
82
|
16
|
|
|
|
|
23
|
grep { push @b, splice @b, R( 9 ), 5 } @t; |
|
256
|
|
|
|
|
336
|
|
83
|
16
|
|
|
|
|
30
|
$R[ $c ] = R( 2**32 ); |
84
|
16
|
|
|
|
|
20
|
@{ $S[ $c++ ] } = @b; |
|
16
|
|
|
|
|
78
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
__END__ |