cipher.pl - Vigenere cipher. Encoding, decoding, cracking.
cipher.pl [-help] [-man] [-encode] [-decode] [-crack] [-try_length] [-key KEY] [-threshold TH] [-ratio RATIO] [-max_length NUM] [-verbose] [-pod] [-ofile OFILE] [IFILE ...]
See below for more description of these switches.
cipher.pl encodes plaintext and either decodes or cracks coded text using the Vigenere cipher. For encoding, the plaintext is supplied in a file IFILE, while the key, which is a string of letters is given on the command line with -key. For decoding the encoded text is supplied in the file IFILE.
The option -freq prints character frequencies and exits without performing any transcoding or cracking.
Before encoding or frequency countng, the iput text is stripped of any non-alphabetic charcters and is converted to upper case. The cracking algorithm assumes that the coded message consists only of characters A-Z.
This program was written for educational purposes.
The option names may be given as unique abbreviations. For example, -dec, or -d rather than -decode.
- -key KEY (string)
cipher key for encoding or decoding.
encode the message in each input IFILE using KEY. encode is the default and does not need to be specified.
decode the encrypted message in each IFILE.
- -ofile OFILE
send output to OFILE rather than standard out (the terminal).
Try to find the key of the encrypted message in IFILE by analyzing character frequencies.
- -try_length LEN (positive integer)
Like -crack, except only keys of length LEN are analyzed.
- -threshold TH (floating point number)
The threshold score at which the code is considered cracked. Default value is
0.1. The key cracking algorithm rejects scores that are higher than TH. A lower value of TH requires that the trial frequency table matches more closely the standard frequency table.
- -ratio RATIO (positive integer)
Only the first
RATIO * key_lengthcharacters of the encrypted message are analyzed when cracking. The default value of RATIO is
1000. Try increasing this value if the algorithm fails to find the key. If RATIO is zero or negative, then the entire encrypted message is analyzed.
- -max_length NUM (positive integer)
The maximum keylength to try when cracking. If this option is not given, the maximum defaults to the length of the encoded message in IFILE.
Compute and print the frequency table of the input file and exit.
Print some informative messages while running.
Write this documentation to the file README.pod.
Encode the text in ulysses.txt with key
joyceand write the result to codedtext.txt.
cipher.pl -key joyce -o codedtext.txt ulysses.txt
Decode the text in codedtext.txt and write the result to decodedtext.txt.
cipher.pl -key joyce -dec -o decodedtext.txt codedtext.txt
Try to find the encryption key used to encode input file codedtext.txt.
cipher.pl -crack codedtext.txt
Encode as above, but write output to standard out.
cipher.pl -key joyce ulysses.txt
The cracking algorithm first searches for a key of length one, then of length two, etc. For each key length it computes the frequencies of characters in the input text that would have been encoded by the same position in the keyword. It then repeatedly rotates this freqency sequence and records the rotation that gives the best match to the average frequencies in english language text. It then averages scores from the best match for each position in the key and compares this to a threshold value. If the average score is below the threshold, then these positions are reported as a likely key and the program exits. Otherwise the keylength is incremented and the algorithm continues.
The score is the average over the alphabet of the relative mean squared deviation of the observed frequency from the frequency standard.
Account for the effect of poisson statistics on the score.
Add support for other languages.
John Lapeyre <firstname.lastname@example.org>