The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Text::Cipher::KeywordAlphabet - Substitution cipher based on a keyword alphabet

SYNOPSIS

        #Create a keyword alphabet with a left shift of 5
        $cipher = new Text::Cipher::KeywordAlphabet("the quick brown fox", -5);

        #Fetch the generated alphabet
        $keyword_alphabet = $cipher->alphabet();

        #Encipher a string
        $ciphered = $cipher->encipher($message);

        #Decipher an enciphered message
        $message = $cipher->decipher($ciphered);

        #Some convenience methods
        $cipher->encipher_scalar(\$some_scalar);
        $cipher->decipher_scalar(\$some_scalar);
        @ciphered = $cipher->encipher_list(@list);
        @list = $cipher->decipher_list(@ciphered);
        $cipher->encipher_array(\@some_array);
        $cipher->decipher_array(\@some_array);

        #Other uses
        $null_cipher = new Text::Cipher::KeywordAlphabet(); #no-op cipher
        $rot13_cipher = new Text::Cipher::KeywordAlphabet(undef, 13); #Caesar cipher

DESCRIPTION

This module generates a monoalphabetic substitution cipher from a set of words, resulting in what's sometimes referred to as a "keyword (generated) alphabet". Here's a good definition, plagiarised from an anonymous source:

"A keyword alphabet is formed by taking a word or phrase, deleting the second and subsequent occurrence of each letter and then writing the remaining letters of the alphabet in order. Encipherment is achieved by replacing each plaintext letter by the letter that appears N letters later in the (cyclic) keyword alphabet."

The keyword alphabet is case-insensitive - both uppercase and lowercase characters will be transformed with the same mapping. The offset (N in the definition above) can be a positive or negative integer.

http://www.trincoll.edu/depts/cpsc/cryptography/substitution.html is an introductory tutorial on how substitution ciphers can be broken. http://www-math.cudenver.edu/~wcherowi/courses/m5410/exsubcip.html contains a full worked example. http://www.muth.org/Robert/Cipher/query_scb.html provides an online substitution cipher breaker.

At the risk of stating the obvious, since substitution ciphers are easy to break, it's advisable not to use them for protecting important data. Look at some of the more heavy-duty ciphers in the Crypt:: namespace which plug into Crypt::CBC if you want to protect data.

METHODS

$obj = new Text::Cipher::KeywordAlphabet($keyword_phrase, $offset)

Create a new keyword alphabet

$keyword_alphabet = $obj->alphabet();

Return the keyword alphabet created by the constructor

$ciphered = $obj->encipher($message)

Enciphers a string using the keyword alphabet

$message = $obj->decipher($ciphered)

Reverse of encipher()

$obj->encipher_scalar(\$some_scalar);

By-reference equivalent of encipher()

$obj->decipher_scalar(\$some_scalar);

By-reference equivalent of decipher()

@ciphered = $obj->encipher_list(@list);

Convenience method provided by Text::Cipher

@list = $obj->decipher_list(@ciphered);

Reverse of encipher_list().

$obj->encipher_array(\@some_array);

Convenience method provided by Text::Cipher

$obj->decipher_array(\@some_array);

Reverse of encipher_array().

VERSION

See $Text::Cipher::KeywordAlphabet::VERSION. Last edit: $Revision: 1.5 $ on $Date: 2005/03/20 20:02:11 $

BUGS

None known. This module has not been used heavily in production so it's not impossible a bug may have slipped through the unit tests. Bug reports are welcome, particularly with patches & test cases.

AUTHOR

John Alden <johna@cpan.org>

SEE ALSO

Text::Cipher and Regexp::Tr

Useful building blocks for substitution ciphers

Text::Shift and Crypt::Rot13

Caesar (aka shift or rot-N) ciphers (see http://www.trincoll.edu/depts/cpsc/cryptography/caesar.html)

Crypt::Caesar

Crack Caesar ciphers using letter frequency (see http://www.trincoll.edu/depts/cpsc/cryptography/caesar.html)

Crypt::Vigenere

Vigenere polyalphabetic cipher (see http://www.trincoll.edu/depts/cpsc/cryptography/vigenere.html)

Crypt::Enigma and Crypt::OOEnigma

Implementations of Enigma ciphers (see http://www.trincoll.edu/depts/cpsc/cryptography/enigma.html)

COPYRIGHT AND LICENSE

Copyright 2005 by John Alden

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.