Crypt-OOEnigma
view release on metacpan or search on metacpan
lib/Crypt/OOEnigma.pm view on Meta::CPAN
# sjb Mon Mar 18 20:55:53 GMT 2002
#
package Crypt::OOEnigma;
=head1 NAME
Crypt::OOEnigma - A World War II Enigma machine in a flexible OO framework
=head1 SYNOPSIS
use Crypt::OOEnigma;
my $enigma = Crypt::OOEnigma->new();
# OR set the default rotors' start positions
Crypt::OOEnigma->new( start_positions => [10,20,5] );
# OR choose rotors from the set (0..5)
Crypt::OOEnigma->new( rotor_choice => [3,4,5]);
# OR both
Crypt::OOEnigma->new( rotor_choice => [3,4,5],
start_positions => [10,20,5] );
my $cipher = $enigma->encipher("Some Text");
my $decode = $enigma->decipher($cipher);
# OR, since Enigma's are self-inverse:
my $decode = $enigma->encipher($cipher);
=cut
use Carp;
use vars qw($VERSION);
$VERSION="0.3";
use Crypt::OOEnigma::Military;
use Crypt::OOEnigma::Rotor ;
=head1 DESCRIPTION
=head2 What is an Enigma?
The Enigma Machine was a much-used encryption device in the Second World War.
It was an electrical device, somewhat like a typewriter, combining substitution
and rotation ciphers in such a manner that the resulting overall cipher was
difficult to break, unlike the constituent ciphers. The machine could decode as
well as encoding messages.
In short, the electrical Enigma is constructed from a number of rotors -
usually 3, each of which implements a simple substitution cipher on the letters
of the alphabet only, and a reflector. The reflector is a self-inverse simple
substitution cipher with no short circuits. On receiving a clear-text message
for transmission, the operator first replaces all spaces with the letter X,
before typing the message into the machine. As each key is pressed, a current
passes through each rotor, the reflector and back through the rotors in reverse
order to produce the cipher-text message. As the message is processed, the
first rotor rotates once for every letter that is encoded, the second rotor
once every 26 letters, the third rotor every 26 squared letters and so on.
The Enigma is configured by selecting several rotors from a larger set, placing
them in a particular order and a particular start position. Received messages
are decoded by setting the Enigma to the same state as the encoding Enigma and
processing the message again. The result is clear text with the letter X
instead of spaces.
For a good description of the Enigma, including some interesting exercises, see
Part IV of "The Pleasures of Counting" by T W Korner, Cambridge University
Press.
=head2 The Commercial Enigma
The commercial Enigma typically consists of 3 rotors and a reflector. A
Commercial Enigma is provided in the package.
=head2 The Military Enigma
It turns out that the Commercial Enigma is relatively easily cracked by brute
force methods (see Korner) and that it can be easily strengthened by the
addition of a simple device known as the plugboard. The plugboard is a set of
electrical plugs implementing the identity substitution (A -> A, B -> B etc)
with a number of pairs of letters - say, 6 - swapped. The plugboard sits
between the operator's keyboard and the commercial enigma and it has an impact
far in excess of its complexity.
A Military Enigma Machine is included in the package.
=head2 The OOEnigma Module
For simplicity, this OOEnigma module supplies a number of rotors and a
military enigma machine so that the user can do one of:
=over 4
=item * Use a default Enigma
=item * Choose 3 rotors
=item * Choose start positions
=item * Choose both 3 rotors and their start positions
=back
And the Enigma takes care of the rest. Users who wish to use their own
substitution codes or create their own Enigmas should see the documentation for
the individual modules.
=head2 Creating your own Enigmas.
Enigmas based on an arbitrary number of rotors and using rotors, reflectors
and plugboards with any reasonable cipher may be easily constructed. The
user creates the required Rotor, Reflector and Plugboard objects then uses
them to instantiate either a Military or Commercial Enigma.
=head1 NOTES
None
=head1 BUGS and CAVEATS
=head2 Enigma is weak!
( run in 0.518 second using v1.01-cache-2.11-cpan-2398b32b56e )