🗝️ 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
- Case is preserved and the key ignores it - a capital A returns a capital L, and lemon matches LEMON.
- Only A-Z moves. Spaces, digits, punctuation and accented letters pass through untouched and do not advance the keyword, so word shapes stay visible in the output.
- Non-letters are stripped from the keyword. Enter LEMON, please! and you are really using the eleven-letter key LEMONPLEASE, which gives a different ciphertext from LEMON.
- Decoding is silent when it fails. A wrong keyword returns plausible-looking rubbish rather than an error, because nothing in the cipher checks itself.
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.