Text::Cipher::KeywordAlphabet - Substitution cipher based on a keyword alphabet
#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
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.
Create a new keyword alphabet
Return the keyword alphabet created by the constructor
Enciphers a string using the keyword alphabet
Reverse of encipher()
By-reference equivalent of encipher()
By-reference equivalent of decipher()
Convenience method provided by Text::Cipher
Reverse of encipher_list().
Reverse of encipher_array().
See $Text::Cipher::KeywordAlphabet::VERSION. Last edit: $Revision: 1.5 $ on $Date: 2005/03/20 20:02:11 $
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.
John Alden <johna@cpan.org>
Useful building blocks for substitution ciphers
Caesar (aka shift or rot-N) ciphers (see http://www.trincoll.edu/depts/cpsc/cryptography/caesar.html)
Crack Caesar ciphers using letter frequency (see http://www.trincoll.edu/depts/cpsc/cryptography/caesar.html)
Vigenere polyalphabetic cipher (see http://www.trincoll.edu/depts/cpsc/cryptography/vigenere.html)
Implementations of Enigma ciphers (see http://www.trincoll.edu/depts/cpsc/cryptography/enigma.html)
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.
To install Text::Cipher::KeywordAlphabet, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::Cipher::KeywordAlphabet
CPAN shell
perl -MCPAN -e shell install Text::Cipher::KeywordAlphabet
For more information on module installation, please visit the detailed CPAN module installation guide.