What is the Vigenère cipher?
The Vigenère cipher is a polyalphabetic substitution cipher: instead of one fixed shift for the whole message, each letter is shifted by an amount taken from a keyword. The keyword is repeated along the message, so the letter A in the key means shift 0, B means shift 1, and so on up to Z for shift 25. Each key letter therefore acts like a separate Caesar cipher.
For about three centuries the cipher was nicknamed "le chiffre indéchiffrable" (the indecipherable cipher). Friedrich Kasiski published a general method for breaking it in 1863, and Charles Babbage had found the same idea earlier without publishing it.
Encryption and decryption formulas
Number the letters A = 0, …, Z = 25 and let the key have m letters K(0), …, K(m − 1). Encryption is C(i) = (P(i) + K(i mod m)) mod 26 and decryption is P(i) = (C(i) − K(i mod m)) mod 26.
Worked example: encrypt ATTACKATDAWN with the key LEMON. The repeated key is LEMONLEMONLE. The first letter is A + L = 0 + 11 = 11, which is L. The second is T + E = 19 + 4 = 23, which is X. Continuing in the same way gives LXFOPVEFRNHR.
Why it is stronger than Caesar, and why it can still be broken
Because the same plaintext letter can become different cipher letters, the letter frequencies of the ciphertext are flattened and a simple frequency count no longer reveals the key. The security grows with the key length, and a random key as long as the message that is used only once is the unbreakable one-time pad.
With a short repeated keyword, however, the cipher is weak. Repeated words in the plaintext can line up with the same part of the key, producing repeated groups in the ciphertext. The distance between such groups reveals the key length m (Kasiski examination). Once m is known, every m-th letter was shifted by the same amount, and each of these groups is an ordinary Caesar cipher that frequency analysis solves.
Tips for using the calculator
Enter the text, the keyword and choose encrypt or decrypt.
- The key may contain letters only; upper and lower case give the same shifts.
- The key advances only on letters. Spaces and punctuation are copied unchanged and do not consume a key letter. Other programs may advance the key on every character, so results can differ from theirs.
- A one-letter key turns the cipher into a Caesar cipher.
Worked examples
These examples are computed by the same engine as the calculator above, so you can compare each step with your own working.
ATTACKATDAWN / LEMON
- Mode:
Encrypt - Text:
ATTACKATDAWN - Keyword:
LEMON
Ciphertext
LXFOPVEFRNHR
key LEMON (5 letters)
Convention used: the key advances only on letters. Spaces and punctuation are copied and do not use up a key letter. Some other programs advance the key on every character, which gives different output.
Step-by-step solution
Formula used
C(i) = (P(i) + K(i mod m)) mod 26
A = 0, …, Z = 25; m = key length = 5
NoteNumber the letters and the key
A = 0, B = 1, …, Z = 25.
Key LEMON = (11, 4, 12, 14, 13), so the shifts repeat with period 5.
NoteWrite the key under the text
Each key letter is repeated to match the number of letters in the message.
Plain : ATTACKATDAWN
Key : LEMONLEMONLE
CalculateAdd the key letter to each plaintext letter
x + k, then mod 26
| # | Letter | x | Key letter | k | x + k | mod 26 | Result |
|---|
| 1 | A | 0 | L | 11 | 11 | 11 | L |
| 2 | T | 19 | E | 4 | 23 | 23 | X |
| 3 | T | 19 | M | 12 | 31 | 5 | F |
| 4 | A | 0 | O | 14 | 14 | 14 | O |
| 5 | C | 2 | N | 13 | 15 | 15 | P |
| 6 | K | 10 | L | 11 | 21 | 21 | V |
| 7 | A | 0 | E | 4 | 4 | 4 | E |
| 8 | T | 19 | M | 12 | 31 | 5 | F |
| 9 | D | 3 | O | 14 | 17 | 17 | R |
| 10 | A | 0 | N | 13 | 13 | 13 | N |
| 11 | W | 22 | L | 11 | 33 | 7 | H |
| 12 | N | 13 | E | 4 | 17 | 17 | R |
CheckVerify by reversing
Decrypting the result with the same key gives back the original text: ✓ yes
ResultCiphertext
LXFOPVEFRNHR
Decrypt LXFOPVEFRNHR
- Mode:
Decrypt - Text:
LXFOPVEFRNHR - Keyword:
LEMON
Plaintext
ATTACKATDAWN
key LEMON (5 letters)
Convention used: the key advances only on letters. Spaces and punctuation are copied and do not use up a key letter. Some other programs advance the key on every character, which gives different output.
Step-by-step solution
Formula used
P(i) = (C(i) − K(i mod m)) mod 26
A = 0, …, Z = 25; m = key length = 5
NoteNumber the letters and the key
A = 0, B = 1, …, Z = 25.
Key LEMON = (11, 4, 12, 14, 13), so the shifts repeat with period 5.
NoteWrite the key under the text
Each key letter is repeated to match the number of letters in the message.
Cipher: LXFOPVEFRNHR
Key : LEMONLEMONLE
CalculateSubtract the key letter from each cipher letter
y − k, then mod 26
| # | Letter | y | Key letter | k | y − k | mod 26 | Result |
|---|
| 1 | L | 11 | L | 11 | 0 | 0 | A |
| 2 | X | 23 | E | 4 | 19 | 19 | T |
| 3 | F | 5 | M | 12 | -7 | 19 | T |
| 4 | O | 14 | O | 14 | 0 | 0 | A |
| 5 | P | 15 | N | 13 | 2 | 2 | C |
| 6 | V | 21 | L | 11 | 10 | 10 | K |
| 7 | E | 4 | E | 4 | 0 | 0 | A |
| 8 | F | 5 | M | 12 | -7 | 19 | T |
| 9 | R | 17 | O | 14 | 3 | 3 | D |
| 10 | N | 13 | N | 13 | 0 | 0 | A |
| 11 | H | 7 | L | 11 | -4 | 22 | W |
| 12 | R | 17 | E | 4 | 13 | 13 | N |
CheckVerify by reversing
Encrypting the result with the same key gives back the original text: ✓ yes
ResultPlaintext
ATTACKATDAWN
Mixed text, key KEY
- Mode:
Encrypt - Text:
Meet me at noon, by the bridge! - Keyword:
key
Ciphertext
Wicd qc kx lysl, lc rri zbmbqi!
key KEY (3 letters)
Convention used: the key advances only on letters. Spaces and punctuation are copied and do not use up a key letter. Some other programs advance the key on every character, which gives different output.
Step-by-step solution
Formula used
C(i) = (P(i) + K(i mod m)) mod 26
A = 0, …, Z = 25; m = key length = 3
NoteNumber the letters and the key
A = 0, B = 1, …, Z = 25.
Key KEY = (10, 4, 24), so the shifts repeat with period 3.
NoteWrite the key under the text
Each key letter is repeated to match the number of letters in the message.
Plain : MEETMEATNOONBYTHEBRIDGE
Key : KEYKEYKEYKEYKEYKEYKEYKE
CalculateAdd the key letter to each plaintext letter
x + k, then mod 26
| # | Letter | x | Key letter | k | x + k | mod 26 | Result |
|---|
| 1 | M | 12 | K | 10 | 22 | 22 | W |
| 2 | e | 4 | E | 4 | 8 | 8 | i |
| 3 | e | 4 | Y | 24 | 28 | 2 | c |
| 4 | t | 19 | K | 10 | 29 | 3 | d |
| 5 | m | 12 | E | 4 | 16 | 16 | q |
| 6 | e | 4 | Y | 24 | 28 | 2 | c |
| 7 | a | 0 | K | 10 | 10 | 10 | k |
| 8 | t | 19 | E | 4 | 23 | 23 | x |
| 9 | n | 13 | Y | 24 | 37 | 11 | l |
| 10 | o | 14 | K | 10 | 24 | 24 | y |
| 11 | o | 14 | E | 4 | 18 | 18 | s |
| 12 | n | 13 | Y | 24 | 37 | 11 | l |
| 13 | b | 1 | K | 10 | 11 | 11 | l |
| 14 | y | 24 | E | 4 | 28 | 2 | c |
| 15 | t | 19 | Y | 24 | 43 | 17 | r |
| 16 | h | 7 | K | 10 | 17 | 17 | r |
| 17 | e | 4 | E | 4 | 8 | 8 | i |
| 18 | b | 1 | Y | 24 | 25 | 25 | z |
| 19 | r | 17 | K | 10 | 27 | 1 | b |
| 20 | i | 8 | E | 4 | 12 | 12 | m |
| 21 | d | 3 | Y | 24 | 27 | 1 | b |
| 22 | g | 6 | K | 10 | 16 | 16 | q |
| 23 | e | 4 | E | 4 | 8 | 8 | i |
CheckVerify by reversing
Decrypting the result with the same key gives back the original text: ✓ yes
ResultCiphertext
Wicd qc kx lysl, lc rri zbmbqi!
Frequently asked questions
Is the Vigenère key case-sensitive?
No. The keys LEMON, lemon and Lemon all give the same shifts. Only the letters A to Z are allowed in the key.
Why do spaces not use up a key letter?
In the usual textbook convention the key moves only when a letter is enciphered. If another tool advances the key on spaces or punctuation too, its output will differ for texts that contain them.
What if the key is shorter than the message?
The key is simply repeated from the beginning as many times as needed. The shift for letter number i is the key letter at position i mod m.
How is the Vigenère cipher broken?
Find the key length with the Kasiski examination or the index of coincidence, split the ciphertext into that many columns, and solve each column as a Caesar cipher with frequency analysis.
Is a longer key always better?
A longer key is harder to attack, but the cipher remains weak against modern analysis unless the key is random, as long as the message and never reused.