Polyalphabetic Cipher — Definition, Formula & Example
A polyalphabetic cipher is a secret code that switches between several different letter substitutions as it moves through a message. The same plaintext letter can therefore turn into different ciphertext letters in different positions.
A polyalphabetic substitution cipher uses more than one substitution alphabet, choosing which one to apply from the letter's position (or from a key stream). In the most common (periodic) form, a cycle of alphabets is used, with alphabet on the letter in position ; non-periodic forms such as the autokey cipher also exist. In its best-known form, the Vigenère cipher, each letter is identified with an integer in . A keyword then defines the encryption .
Key Formula
Where:
- = Number of the plaintext letter in position i (A = 0, B = 1, ..., Z = 25), counting positions from i = 0
- = Number of the ciphertext letter in position i
- = Number of the keyword letter used at position i. The keyword repeats.
- = Length of the keyword (the number of different shifts in the cycle)
Worked Example
Problem: Encrypt the word MOON with a Vigenère cipher using the keyword KEY. Use A = 0, B = 1, ..., Z = 25.
Step 1: Convert the letters to numbers. Repeat the keyword under the plaintext until it covers every letter, so KEY becomes KEYK.
Step 2: Add each pair and reduce mod 26. Only the third sum is 26 or more, so only it wraps around.
Step 3: Convert the results back to letters: 22 = W, 18 = S, 12 = M, 23 = X.
Answer: MOON encrypts to WSMX. The two O's became S and M because they used different key letters. A single-shift (Caesar) cipher could never do that.
Why It Matters
A Caesar cipher sends every E to the same letter, so you can break it by counting which letter shows up most often. A polyalphabetic cipher spreads each letter across several ciphertext letters, and this defeated simple frequency analysis for about 300 years, until Friedrich Kasiski published a general attack in 1863. The same idea, taken to a random key as long as the message, gives the one-time pad, which is studied in intro cryptography and computer security courses.
Common Mistakes
Mistake: Stopping at a sum like 38 and treating it as the answer, or subtracting 25 instead of 26 to wrap around.
Correction: The alphabet has 26 positions (0 through 25), so every sum must be reduced mod 26. Since 38 − 26 = 12, the letter is M. Any result of 26 or more is not yet a valid letter.
