Text::Cipher - Very flexible base class for text ciphers.
# WITHIN MAIN use Text::Cipher; my $obj = Text::Cipher->new($domain,$mapping); #Constructor my $storage = $obj->encipher("some string"); #String op $obj->encipher_scalar(\$some_scalar); #Scalar ref op my @big_storage = $obj->encipher_list("2nd string", #List operator "and another", "and more", "yet more"); $obj->encipher_array(\@some_array); #Array operator Text::Cipher->clean(); #Memory cleanup # AS INHERITED BASE CLASS package Text::Cipher::NewCipher; @ISA = qw(Text::Cipher); sub new { my $class = shift; ... ... return $class->SUPER::new($from,$to); } # Text::Cipher::NewCipher is automatically supplied the cipher # methods. # Aliasing example: make Text::Cipher::NewCipher::flush operate # just like Text::Cipher::clean. BEGIN { *flush = \&Crypt::Cipher::clean };
Provides a standard interface and simple methods for ciphers of various kinds, saving on development time and redundant code.
This method is the constructor for the Text::Cipher class. When called as Text::Cipher->new(DOMAIN, MAPPING, MODS), it creates an object mapping each letter in DOMAIN to its respective letter in MAPPING. MODS are modifieres to the cipher as per the tr/// operator.
Performs the cipher on the string and returns the enciphered value.
This method takes a reference to a scalar (note that it does not create the reference to the scalar) and performs the cipher upon the scalar it refers to. It returns true if anything in the scalar was changed through the application of the cipher.
Returns the list after applying $obj->encipher on every element.
Calls $obj->encipher on every element in the array pointed to by the ARRAYREF.
Performs operations to recover memory, which may or may not make a substantial change.
If you just want to use the methods provided to you by the class, all you have to do is end your constructor with the following code snippet:
return $class->SUPER::new($from,$to);
The $class variable should be the name of your class, and $from should contain the letters your cipher will change (aka: SEARCHLIST) while $to should contain the letters your cipher will move things over to (aka: REPLACEMENTLIST).
If you want to overload a method (the "new" method is popular to overload, as is the "clean" method), then just be sure to end your new method with a call to this class's method.
# Example sub encipher { my $obj = shift; ... return $obj->SUPER::encipher(@params); }
If you are trying to do something even fancier, please ensure that any other impelementation of Text::Cipher or any other cipher built on Text::Cipher and your code would still function. Generally, this can be acheived by defining a class verison of $obj-encipher> and $obj-encipher_scalar>, as most the other methods are built in reference to those two.
$obj-
By default, set to join("","A".."Z"), but not explicitly defined as such. This value should be set as a string which contains all the "capital" or "big" values of the alphabet in which you are working, starting at the "first" letter and going to the "last" letter.
By default, set to join("","a".."z"), but not explicitly defined as such. This value should be a string which contains all the values of the lowercase alphabet in which you are working, starting at the "first" letter and going to the "last" letter.
By default, set to join("",0..9), but not explicitly defined as such. This value should be a string which contains all the values of the numerical alphabet in which you are working, starting at the "first" number and going to the "last" number.
Tested under Perl 5.6, thanks to John Alden.
Renamed to Text::Cipher in order to better represent its purpose (most text ciphers are not secure and applications to non-text values are unintuitive). Provided alphabet constants and registered with PAUSE.
Fixed minor inheritance bugs and documentation. Also fixed a major bug occuring when used in list context.
Original version; created by h2xs 1.22 with options
-ABCX -n Crypt::Cipher
Text::Shift: One cipher built on this system
Robert Fischer, <chia@cpan.org>
Copyright 2003 by Robert Fischer
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
5 POD Errors
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head3'
=back without =over
=back doesn't take any parameters, but you said =back 4
To install Text::Cipher, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::Cipher
CPAN shell
perl -MCPAN -e shell install Text::Cipher
For more information on module installation, please visit the detailed CPAN module installation guide.