🗝️ Vigenère Cipher

Encode or decode text using the Vigenère cipher, a keyword-based shift cipher stronger than a simple Caesar shift. Non-letter characters are left unchanged and don't advance the keyword.

Each letter gets its own shift

The keyword is repeated across the message and every letter is moved by the alphabet position of the key letter above it, counting A as 0:

encode:  C = (P + K) mod 26        decode:  P = (C - K + 26) mod 26

plain    A  T  T  A  C  K  A  T  D  A  W  N
key      L  E  M  O  N  L  E  M  O  N  L  E
cipher   L  X  F  O  P  V  E  F  R  N  H  R

The two T's become X and F, and that is the point: a repeated letter no longer gives a repeated symbol, which is what defeats the frequency attack that breaks a Caesar shift. Attack at dawn! with the key lemon gives Lxfopv ef rnhr!.

What the keyword does and does not cover

This is a puzzle, not protection. The cipher has been broken since the 1860s: the key length falls out of the spacing between repeated fragments, and each position is then a simple Caesar shift. For anything real, use AES encryption instead.

Frequently asked questions

How do you encrypt ATTACK AT DAWN with the key LEMON?

It becomes LXFOPV EF RNHR, the textbook example: the key repeats as LEMONLEMONLE across the twelve letters, and the spaces stay put.

How long should the keyword be?

Longer than the patterns you want hidden. A five-letter key on a long message repeats constantly and is easy to recover; only a key as long as the message, used once, is unbreakable.

Are spaces and punctuation encrypted too?

No. They are copied through unchanged and do not consume a key letter, so word lengths survive intact. Remove the spaces before encoding if that matters.