line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Smithy; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
41673
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
97
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1613
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Crypt::Smithy - Perl implementation of the 'Smithycode' cipher. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.01 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @password = ( 1, 1, 25, 3, 5, 8, 13, 21 ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use Crypt::Smithy; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $s = Crypt::Smithy->new(); |
25
|
|
|
|
|
|
|
print $s->encrypt_string('jackiefisterwhoareyoudreadnough'); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
print $s->decrypt_string('jaeiextostgpsacgreamqwfkadpmqzv'), |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$s->set_password(1, 1, 2, 3, 5, 8, 13, 21); # Fibonacci |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
I implements an algorithm used to embed a code in the |
34
|
|
|
|
|
|
|
2006 judgement in the Da Vinci Code copyright case. |
35
|
|
|
|
|
|
|
Crypthographically it is I and is for entertainment |
36
|
|
|
|
|
|
|
and educational purposes only. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 METHODS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 new |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Constructor |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new { |
47
|
1
|
|
|
1
|
1
|
970
|
my ( $class, %param ) = @_; |
48
|
1
|
|
|
|
|
4
|
my $self = {}; |
49
|
1
|
|
|
|
|
4
|
bless( $self, $class ); |
50
|
1
|
|
|
|
|
3
|
return $self; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 set_password |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Set another alphabet than the default (1, 1, 25, 3, 5, 8, 13, 21). |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
0
|
1
|
0
|
sub set_password { my $self = shift; @password = @_ } |
|
0
|
|
|
|
|
0
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Return true if uppercase, otherwise false |
62
|
|
|
|
|
|
|
sub _is_uppercase { |
63
|
296
|
|
|
296
|
|
812
|
my ( $self, $c ) = @_; |
64
|
296
|
100
|
|
|
|
1370
|
( $c =~ m/^[A-Z]$/ ) ? return 1 : return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Return index of 'A' or 'a' depending on case |
68
|
|
|
|
|
|
|
sub _get_base { |
69
|
288
|
|
|
288
|
|
334
|
my ( $self, $c ) = @_; |
70
|
288
|
100
|
|
|
|
441
|
return ( $self->_is_uppercase($c) ) ? ord('A') : ord('a'); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Decrypt a character |
74
|
|
|
|
|
|
|
sub _decrypt_char { |
75
|
70
|
|
|
70
|
|
94
|
my ( $self, $n, $c ) = @_; |
76
|
70
|
|
|
|
|
107
|
my $i = ord($c) - $self->_get_base($c); |
77
|
70
|
|
|
|
|
126
|
my $p = ( $i + $password[ $n % scalar(@password) ] - 1 ) % 26; |
78
|
70
|
|
|
|
|
102
|
return chr( $self->_get_base($c) + $p ); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Decrypt a character |
82
|
|
|
|
|
|
|
sub _encrypt_char { |
83
|
70
|
|
|
70
|
|
108
|
my ( $self, $n, $c ) = @_; |
84
|
70
|
|
|
|
|
148
|
my $i = ord($c) - $self->_get_base($c); |
85
|
70
|
|
|
|
|
127
|
my $p = ( $i - $password[ $n % scalar(@password) ] + 1 ) % 26; |
86
|
70
|
|
|
|
|
120
|
return chr( $self->_get_base($c) + $p ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 decrypt_string |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Decrypt a string using the current password. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub decrypt_string { |
96
|
2
|
|
|
2
|
1
|
4
|
my ( $self, $s ) = @_; |
97
|
2
|
|
|
|
|
22
|
my $n = 0; |
98
|
2
|
|
|
|
|
15
|
return join( '', map { $self->_decrypt_char( $n++, $_ ) } split( '', $s ) ); |
|
62
|
|
|
|
|
113
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 encrypt_string |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Encrypt a string using the current password. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub encrypt_string { |
108
|
2
|
|
|
2
|
1
|
4
|
my ( $self, $s ) = @_; |
109
|
2
|
|
|
|
|
3
|
my $n = 0; |
110
|
2
|
|
|
|
|
13
|
return join( '', map { $self->_encrypt_char( $n++, $_ ) } split( '', $s ) ); |
|
62
|
|
|
|
|
121
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 AUTHOR |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Andreas Faafeng, C<< >> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 BUGS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Please report any bugs or feature requests to C
|
120
|
|
|
|
|
|
|
rt.cpan.org>, or through the web interface at |
121
|
|
|
|
|
|
|
L. I |
122
|
|
|
|
|
|
|
will be notified, and then you'll automatically be notified of |
123
|
|
|
|
|
|
|
progress on your bug as I make changes. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SUPPORT |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
perldoc Crypt::Smithy |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
You can also look for information at: |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=over 4 |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
L |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item * CPAN Ratings |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item * Search CPAN |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
L |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=back |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
The wikipedia article L has |
156
|
|
|
|
|
|
|
a lenghty explaination of the origin of the cipher. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 SEE ALSO |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Copyright 2011 Andreas Faafeng. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
167
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
168
|
|
|
|
|
|
|
the Free Software Foundation; version 2 dated June, 1991 or at your |
169
|
|
|
|
|
|
|
option any later version. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but |
172
|
|
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
173
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
174
|
|
|
|
|
|
|
General Public License for more details. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
A copy of the GNU General Public License is available in the source |
177
|
|
|
|
|
|
|
tree; if not, write to the Free Software Foundation, Inc., 59 Temple |
178
|
|
|
|
|
|
|
Place - Suite 330, Boston, MA 02111-1307, USA. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
1; # End of Crypt::Smithy |