---
title: "Vigenère"
description: "A keyword picks a different Caesar shift for each letter. Keyspace 26 to the key length, weakness is the period."
canonical_url: "https://ciphers.agntn.dev/ciphers/vigenere"
---
# Vigenère

> A keyword picks a different Caesar shift for each letter. Keyspace 26 to the key length, weakness is the period.

<cipher-facts name="vigenere">



</cipher-facts>

The keyword repeats under the plaintext and each letter is shifted by the key letter above it, A meaning 0. Only letters advance the key. Spaces and punctuation pass through without eating a key position, which is why `"ATTACK AT DAWN"` and `"ATTACKATDAWN"` agree letter for letter. Key is letters only, case doesn't matter.

```ts
const vigenere = create("vigenere");
vigenere.encode("ATTACK AT DAWN", { key: "LEMON" }).text; // "LXFOPV EF RNHR"
vigenere.encode("ATTACK AT DAWN", { key: "LEMON", stripNonAlpha: true }).text; // "LXFOPVEFRNHR"
vigenere.decode("LXFOPV EF RNHR", { key: "LEMON" }).text; // "ATTACK AT DAWN"
vigenere.encode("HELLO"); // throws MissingOptionError: key
```

Keyspace is 26 to the key length, which sounds like a lot until you notice that every n-th letter is a plain Caesar. So the attack is finding the period. [`analyzeFrequency`](https://ciphers.agntn.dev/guide/analysis) on the whole text gives an IC near 0.038; on every fifth letter of the LEMON example it climbs back toward English.

[Trithemius](https://ciphers.agntn.dev/ciphers/trithemius) is a Vigenère whose key is the alphabet itself, and [Gronsfeld](https://ciphers.agntn.dev/ciphers/gronsfeld) one whose key is a number. [Running key](https://ciphers.agntn.dev/ciphers/running-key) takes a whole page of a book.


## Sitemap

See the full [sitemap](https://ciphers.agntn.dev/sitemap.md) for all pages.
