Skip to content
K Knidox Search…
Computer Science · Ciphers

Vigenère Cipher

Encode or decode a Vigenère cipher with a keyword — the shift changes letter by letter.

Mode
Ciphertext
LXFOPVEFRNHR
Key alignment

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.

AL11
TE4
TM12
AO14
CN13
KL11
AE4
TM12
DO14
AN13
WL11
NE4
Classic example — tap to load

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.

Cᵢ = (Pᵢ + Kᵢ) mod 26

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. 1
    Choose Encode or Decode. Encode adds the keyword shifts; Decode subtracts them to reverse the process.
  2. 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. 3
    Type your message. Enter ATTACKATDAWN. Each letter pairs with the keyword letter above it.
  4. 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. 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).

PlaintextKeywordSum mod 26Ciphertext
A (0)L (11)11L
T (19)E (4)23X
T (19)M (12)5F
A (0)O (14)14O
C (2)N (13)15P

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.

How is the Vigenère cipher different from a Caesar cipher?
A Caesar cipher shifts every letter by the same fixed amount. Vigenère uses a repeating keyword so the shift changes letter by letter, which hides the letter-frequency patterns a single Caesar shift leaves behind.
Is the Vigenère cipher secure today?
No. The repeating keyword is its downfall — the Kasiski examination and Friedman test recover the key length, after which the message breaks into simple Caesar ciphers. Use it only to learn how classical ciphers work, never to protect real data.
What happens to spaces, numbers, and punctuation?
They pass through unchanged and, importantly, do not advance the keyword. Only letters are shifted, so the keyword stays aligned with the letters of your message.
Does the keyword letter A do anything?
No. A means a shift of 0, so any position lined up with A is copied unchanged. That is why keywords made only of A’s leave the whole message as plaintext.
Why does ATTACKATDAWN with key LEMON give LXFOPVEFRNHR?
The keyword repeats as LEMONLEMONLE beneath the message. Adding each pair modulo 26 — A+L→L, T+E→X, T+M→F, and so on — produces LXFOPVEFRNHR. Subtracting the same keyword reverses it.
Does the case of my text matter?
Case is preserved in the output, and the keyword is read case-insensitively. An uppercase plaintext letter stays uppercase and a lowercase one stays lowercase after the shift.