Encryption replaces each letter in the alphabet by a letter located at a specific fixed distance from that letter.
Here:
- : plaintext letter, encoded as an integer 0 (a) to 25 (z)
- : the shift value, the secret key
Viewed as a stream cipher, a stream of plaintext characters and a stream of keys are input to , producing a stream of ciphertext characters . The shift cipher’s keystream is a repeating sequence of just one key value .
Breaking the Shift Cipher
The shift cipher has only 26 possible keys, so an attacker can try each in turn until the correct plaintext is recognized. This is called an exhaustive key search attack.
Character frequency analysis computes the frequency of characters in the ciphertext and matches it against the standard character frequency table of the language.
- Replace the highest frequency ciphertext characters with the corresponding plaintext characters by frequency rank.
- The 6 most frequent English characters account for approximately 44.4% of characters in a block of text, so the correct key is usually found quickly.
- Trial and error over different orderings of characters may be needed to find the correct key.
A more rigorous technique computes the statistical distance between the standard character frequency distribution and the ciphertext’s frequency distribution, for each candidate shift .
Here:
- : random variable distributed according to the standard character frequency
- : random variable distributed according to the shift
- : the set of values which can occur for or with non-zero probability
Computing for each of the 26 values of and taking the smallest value gives the secret key.