The Vigenère cipher is a Caesar cipher with a changing shift. A keyword is written repeatedly under the message, and each letter is shifted by the value of the key letter above it: A shifts by 0, B by 1, K by 10. Because the same plaintext letter is encrypted differently depending on its position, simple frequency analysis fails, and for three centuries the method was known as “le chiffre indéchiffrable”, the indecipherable cipher.
The idea was first published by Giovan Battista Bellaso in 1553; Blaise de Vigenère described a stronger autokey version in 1586 and got the credit. Charles Babbage and later Friedrich Kasiski (1863) broke it by finding repeated fragments in the ciphertext, whose distances reveal the key length; each column can then be solved as a simple Caesar cipher. The longer and more random the key, the harder the attack. A truly random key as long as the message is a one-time pad, which is unbreakable.
Only the letters A–Z are encrypted and the key advances only on letters, so spaces and punctuation stay in place and the case of each letter is kept. Choose autokey to extend the keyword with the message itself, or Beaufort, the reciprocal variant used in some cipher machines, where encryption and decryption are the same operation.
How to use the Vigenère Cipher Encoder and Decoder
- Message
- Keyword
- Mode
- Variant
Everything is calculated in your browser, so results appear instantly and nothing you type is sent to a server.
How it works
Letters are numbered A = 0 to Z = 25. For each letter of the message the next key letter is taken (the keyword repeats; in autokey the plaintext follows the keyword), and the values are added (encrypt) or subtracted (decrypt) modulo 26. Beaufort subtracts the plaintext from the key.
Worked example
Encrypt “Attack at dawn” with key LEMON. The key stream is LEMONL EM ONLE. A (0) + L (11) = 11 = L; T (19) + E (4) = 23 = X; T (19) + M (12) = 31 mod 26 = 5 = F; A + O = O; C + N = P; K + L = V … The result is Lxfopv ef rnhr (12 letters encrypted). With key OMNI, CALCULATOR becomes QMYKIXNBCD.
Letter values
| A | B | C | D | E | F | G | H | I | J | K | L | M |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
Formula
Encrypt: Cᵢ = (Pᵢ + Kᵢ) mod 26 · Decrypt: Pᵢ = (Cᵢ − Kᵢ) mod 26 (A = 0 … Z = 25)
Autokey: key stream = keyword + plaintext · Beaufort: Cᵢ = (Kᵢ − Pᵢ) mod 26
Worked example
Inputs: Message: Attack at dawn; Keyword: LEMON; Mode: Encrypt; Variant: Classic Vigenère (repeating key).
Results: Result = Lxfopv ef rnhr; Message, key stream and result = Text: Attack at dawn
Key: LEMONL EM ONLE
Result: Lxfopv ef rnhr; Letter-by-letter arithmetic = Letter Key letter + key Result
────────────────────────────────────
A L 0 + 11 L
T E 19 + 4 X
T M 19 + 12 F
A O 0 + 14 O
C N 2 + 13 P
K L 10 + 11 V
A E 0 + 4 E
T M 19 + 12 F
D O 3 + 14 R
A N 0 + 13 N
W L 22 + 11 H
N E 13 + 4 R; Key stream = LEMONL EM ONLE; Letters processed = 12; Key length = 5.
Key terms
- Polyalphabetic cipher
- A cipher that uses several substitution alphabets.
- Key stream
- The sequence of key letters lined up with the message.
- Kasiski examination
- Method for finding the key length from repeated ciphertext fragments.
- One-time pad
- A Vigenère-style cipher with a random key as long as the message, provably secure.
Frequently asked questions
How does the Vigenère cipher work?
Each letter is shifted by the matching letter of a repeating keyword: with key LEMON, the 1st letter shifts by L = 11, the 2nd by E = 4, and so on.
What is “HELLO” with key “KEY”?
RIJVS: H + K = R, E + E = I, L + Y = J, L + K = V, O + E = S.
How do I decrypt?
Subtract the key letters instead of adding: Pᵢ = (Cᵢ − Kᵢ) mod 26.
Can the Vigenère cipher be broken?
Yes. Kasiski examination or the index of coincidence reveals the key length, then each position is a Caesar cipher.
What is the Vigenère square (tabula recta)?
A 26 × 26 table of shifted alphabets; the row of the key letter and the column of the plaintext letter meet at the ciphertext letter.
Why do spaces stay the same?
Only letters are encrypted and the key advances only on letters, which is the usual convention.
What is the autokey cipher?
A variant where the key stream continues with the plaintext itself, so the key never repeats.