File Coverage

blib/lib/Crypt/Polybius.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1 2     2   212979 use 5.008;
  2         9  
  2         78  
2 2     2   12 use strict;
  2         3  
  2         71  
3 2     2   13 use warnings;
  2         7  
  2         154  
4              
5             package Crypt::Polybius;
6              
7             our $AUTHORITY = 'cpan:TOBYINK';
8             our $VERSION = '0.003';
9              
10 2     2   7535 use Moo;
  2         52143  
  2         1482  
11 2     2   5801 use namespace::sweep;
  2         63777  
  2         14  
12              
13             with qw(
14             MooX::Traits
15             Crypt::Role::CheckerboardCipher
16             Crypt::Role::LatinAlphabet
17             );
18              
19             1;
20              
21             __END__
22              
23             =pod
24              
25             =encoding utf-8
26              
27             =head1 NAME
28              
29             Crypt::Polybius - implementation of the Polybius square
30              
31             =head1 SYNOPSIS
32              
33             use Crypt::Polybius;
34            
35             # 1 2 3 4 5
36             # 1 A B C D E
37             # 2 F G H I/J K
38             # 3 L M N O P
39             # 4 Q R S T U
40             # 5 V W X Y Z
41             #
42             # ATTACK -> 11 44 44 11 13 25
43             # AT -> 11 44
44             # DAWN -> 14 11 52 33
45            
46             my $square = Crypt::Polybius->new;
47            
48             print $square->encipher('Attack at dawn.'), "\n";
49              
50             =head1 DESCRIPTION
51              
52             This module provides an object-oriented implementation of the
53             B<Polybius square>, or B<Polybius checkerboard>. This cipher is
54             not cryptographically strong, nor completely round-trip-safe.
55              
56             =head2 Roles
57              
58             This class performs the following roles:
59              
60             =over
61              
62             =item *
63              
64             L<Crypt::Role::LatinAlphabet>
65              
66             =item *
67              
68             L<Crypt::Role::CheckerboardCipher>
69              
70             =item *
71              
72             L<MooX::Traits>
73              
74             =back
75              
76             =head2 Constructors
77              
78             =over
79              
80             =item C<< new(%attributes) >>
81              
82             Moose-like constructor.
83              
84             =item C<< new_with_traits(%attributes, traits => \@traits) >>
85              
86             Alternative constructor provided by L<MooX::Traits>.
87              
88             =back
89              
90             =head2 Attributes
91              
92             The following attributes exist. All of them have defaults, and should
93             not be provided to the constructor.
94              
95             =over
96              
97             =item C<< square >>
98              
99             An array of arrays of letters. Provided by
100             L<Crypt::Role::CheckerboardCipher>.
101              
102             =item C<< square_size >>
103              
104             The length of one side of the square, as an integer. Provided by
105             L<Crypt::Role::CheckerboardCipher>.
106              
107             =item C<< encipher_hash >>
108              
109             Hashref used by the C<encipher> method. Provided by
110             L<Crypt::Role::CheckerboardCipher>.
111              
112             =item C<< decipher_hash >>
113              
114             Hashref used by the C<decipher> method. Provided by
115             L<Crypt::Role::CheckerboardCipher>.
116              
117             =back
118              
119             =head2 Object Methods
120              
121             =over
122              
123             =item C<< encipher($str) >>
124              
125             Enciphers a string and returns the ciphertext. Provided by
126             L<Crypt::Role::CheckerboardCipher>.
127              
128             =item C<< decipher($str) >>
129              
130             Deciphers a string and returns the plaintext. Provided by
131             L<Crypt::Role::CheckerboardCipher>.
132              
133             =item C<< preprocess($str) >>
134              
135             Perform pre-encipher processing on a string. C<encipher> calls this, so
136             you are unlikely to need to call it yourself.
137              
138             The implementation provided by L<Crypt::Role::LatinAlphabet> uppercases
139             any lower-case letters, and passes the string through Text::Unidecode.
140             It also replaces any letter B<J> with B<I> because the former is not
141             found in the alphabet provided by L<Crypt::Role::LatinAlphabet>.
142              
143             =item C<< alphabet >>
144              
145             Returns an arrayref of the known alphabet. Provided by
146             L<Crypt::Role::LatinAlphabet>.
147              
148             =back
149              
150             =head2 Class Method
151              
152             =over
153              
154             =item C<< with_traits(@traits) >>
155              
156             Generates a new class based on this class, but adding traits.
157              
158             L<Crypt::Role::ScrambledAlphabet> is an example of an interesting
159             trait that works with this class.
160              
161             =back
162              
163             =head1 BUGS
164              
165             Please report any bugs to
166             L<http://rt.cpan.org/Dist/Display.html?Queue=Crypt-Polybius>.
167              
168             =head1 SEE ALSO
169              
170             L<http://en.wikipedia.org/wiki/Polybius_square>.
171              
172             L<Crypt::Polybius::Greek>.
173              
174             =head1 AUTHOR
175              
176             Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
177              
178             =head1 COPYRIGHT AND LICENCE
179              
180             This software is copyright (c) 2014 by Toby Inkster.
181              
182             This is free software; you can redistribute it and/or modify it under
183             the same terms as the Perl 5 programming language system itself.
184              
185             =head1 DISCLAIMER OF WARRANTIES
186              
187             THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
188             WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
189             MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
190