Vigenère Cipher
Encode or decode a Vigenère cipher with a keyword — the shift changes letter by letter.
Each message letter (top) is encrypted with the keyword letter beneath it — the repeating key is the heart of the Vigenère cipher. Non-letters keep their place and skip the key.
The Vigenère cipher shifts each letter by a repeating keyword instead of one fixed amount. Line the keyword up under the message, add each pair modulo 26, and the shift changes letter by letter. With key LEMON, ATTACKATDAWN encodes to LXFOPVEFRNHR; decoding subtracts the same keyword letters to recover the original.
What a Vigenère cipher is
The Vigenère cipher is a polyalphabetic substitution cipher: rather than shifting every letter by the same number like a Caesar cipher, it uses a repeating keyword to choose a different shift for each position. Each keyword letter names an offset — A shifts by 0, B by 1, up to Z by 25 — and the keyword cycles across the message. Because the same plaintext letter can encrypt to many different ciphertext letters depending on where it lands under the keyword, simple letter-frequency guessing no longer cracks it at a glance.
Pᵢ is the plaintext letter (A=0…Z=25), Kᵢ the keyword letter at the same position; decoding uses Pᵢ = (Cᵢ − Kᵢ + 26) mod 26.
How the keyword cycles
Write the keyword repeatedly beneath the message, one keyword letter per message letter, skipping spaces and punctuation. Convert both letters to numbers (A=0…Z=25), add them, and take the result modulo 26 to get the ciphertext letter. Non-letters pass through untouched and do not consume a keyword letter, so the alignment stays intact. To decode, subtract the keyword letter instead of adding it, adding 26 first so the result never goes negative.
- 1 Choose Encode or Decode. Encode adds the keyword shifts; Decode subtracts them to reverse the process.
- 2 Enter a keyword. Use LEMON. Only its letters matter, and it repeats across the message: L E M O N L E M O N …
- 3 Type your message. Enter ATTACKATDAWN. Each letter pairs with the keyword letter above it.
- 4 Add each pair modulo 26. A(0)+L(11)=11→L, T(19)+E(4)=23→X, T(19)+M(12)=31 mod 26=5→F, and so on.
- 5 Read the result. ATTACKATDAWN with key LEMON gives LXFOPVEFRNHR; decoding it with LEMON returns ATTACKATDAWN.
Worked mapping — ATTACKATDAWN with key LEMON
Each plaintext letter is added to its keyword letter modulo 26 (A=0…Z=25).
| Plaintext | Keyword | Sum mod 26 | Ciphertext |
|---|---|---|---|
| A (0) | L (11) | 11 | L |
| T (19) | E (4) | 23 | X |
| T (19) | M (12) | 5 | F |
| A (0) | O (14) | 14 | O |
| C (2) | N (13) | 15 | P |
Strong for its era, breakable today
Varying the shift makes the Vigenère cipher far stronger than a Caesar cipher, and for roughly three centuries it earned the nickname “le chiffre indéchiffrable” — the indecipherable cipher. Its weakness is the repeating keyword: once you know or guess the key length, the ciphertext splits into several Caesar ciphers that fall to ordinary frequency analysis. The Kasiski examination and the Friedman test both recover that key length, so a Vigenère cipher offers no real security today and should be treated purely as a learning exercise, never for protecting anything sensitive.