Chapter 8
Number Theory

Applet 12. Affine Cipher Calculator

This calculator enciphers and deciphers text using an affine
cipher (such as the Caesar cipher) in which letters are encoded
using the formula C=aP+b (mod 26) where a and b are
whole numbers between 0 and 25 and a is relatively prime to 26.

The calculator also supports general substitution ciphers in which each letter is
replaced by a another letter in a given permutation.

To encipher, enter plain text in the upper text box, and click on the
down-arrow.

To decipher, enter cipher text in the lower text box, and click on the
up-arrow.

Before you can encipher or decipher text, you need to set a cipher. The
two columns of letters on the left show the plaintext letters (blue)
and their cipher substitutions (white).

To set an affine cipher, click "Affine", and enter values for the parameters
a and b. The default values (a=1 and b=3) give
the Caesar cipher. After you click "OK", notice how the pattern of letters
in right hand colums of the main display change.

To set a general substitution cipher, you need to choose letter-by-letter
which substitutions to make. In the table on the right, click on a plaintext letter
(blue background) to select a value, and drop that letter in a ciphertext position
by clicking on a cell with a white background. Repeat until you have set up
the desired substitutions.

If you're trying to crack a cipher and you think you know a few of the
substitutions, it often helps to "empty" the cipher and fill in only the
letters you think you know. When you decipher the message with a partially-completed
cipher, letters that can't be decoded are left blank (like Wheel of Fortune).

Use this tool in conjunction with the
Letter Frequency Analysis Calculator
to experiment with cracking codes. The letter frequency analysis method illustrates
the flaws of letter-substitution ciphers and, more generally, shows how hidden
clues withing ciphertext can reveal weaknesses that expose it to cryptanalysis
(cracking).