What Is the Vigenère Cipher?
The Vigenère cipher is a polyalphabetic substitution cipher invented in 1553 by Giovan Battista Bellaso. It encrypts text by applying a different Caesar shift to each letter based on a repeating keyword. If the keyword is "KEY", the first letter shifts by 10 (K = 10), the second by 4 (E = 4), the third by 24 (Y = 24), then the pattern repeats. This means the same plaintext letter can encrypt to different ciphertext letters depending on its position — the defining feature that separates polyalphabetic ciphers from monoalphabetic ones like Caesar.
For over 300 years, from its invention in 1553 to its first published cryptanalysis in 1863, the Vigenère cipher was called "le chiffre indéchiffrable" — the indecipherable cipher. It defeated every known attack of its era by flattening the letter frequency distribution that makes single-alphabet ciphers trivially breakable. It was not until Friedrich Kasiski and independently Charles Babbage developed new statistical techniques that the cipher finally fell.
How the Vigenère Cipher Works
Encryption Formula
For each plaintext letter at position i, the encryption formula is:
Cᵢ = (Pᵢ + Kᵢ) mod 26
Where Pᵢ is the plaintext letter's position (A = 0, B = 1, … Z = 25), Kᵢ is the corresponding keyword letter's position, and mod 26 wraps the result within the alphabet.
Decryption Formula
Pᵢ = (Cᵢ − Kᵢ + 26) mod 26
Vigenère Cipher Example: Encrypt "ATTACK AT DAWN" with LEMON
Encrypt ATTACK AT DAWN with the keyword LEMON:
| Position | Plaintext | Key Letter | P + K | mod 26 | Ciphertext |
|---|---|---|---|---|---|
| 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 |
Result: ATTACK AT DAWN → LXFOPV EF RNHR
Notice that the two T's at positions 2 and 3 encrypt to different letters (X and F) because they align with different keyword letters (E and M). Similarly, the three A's at positions 1, 4, and 7 become L, O, and E respectively. This varying substitution is exactly what makes frequency analysis ineffective against polyalphabetic ciphers.
Tabula Recta: The Vigenère Square
The tabula recta (also called the Vigenère square or Vigenère table) is the 26×26 grid traditionally used to perform Vigenère encryption by hand. Each row represents a Caesar cipher with a different shift value — row A is shift 0, row B is shift 1, and so on.
To encrypt a letter using the tabula recta:
- Find the row corresponding to the keyword letter.
- Find the column corresponding to the plaintext letter.
- The letter at the intersection is the ciphertext letter.
The preview table on this page shows a 6×6 portion of the full grid. Explore the complete 26×26 tabula recta on our interactive Vigenère table page, where you can click any cell to see the encryption relationship.
Vigenère vs Caesar Cipher
The Vigenère cipher is often described as a polyalphabetic upgrade to Caesar. Here is how the two compare across the properties that matter for practical cryptanalysis:
| Property | Caesar cipher | Vigenère cipher |
|---|---|---|
| Type | Monoalphabetic | Polyalphabetic |
| Key | Single integer shift (0–25) | Keyword of any length |
| Key space | 26 possible keys | 26ⁿ for a keyword of length n |
| Vulnerable to simple frequency analysis? | Yes — letter frequencies stay visible | No — frequencies are flattened across positions |
| First general break | Classical antiquity | 1863 (Kasiski examination) |
| Best modern attack | Brute force all 26 shifts | Kasiski + index of coincidence + frequency analysis per column |
A Vigenère cipher whose keyword is a single letter reduces to a Caesar cipher — Caesar is just Vigenère with n = 1. The jump to any keyword longer than one letter is what makes the cipher resist naive frequency analysis, because each position in the message draws from a potentially different shifted alphabet.
How to Recognize Vigenère Ciphertext
Before attempting to break a cipher, it helps to identify whether you are dealing with Vigenère encryption. Several characteristics distinguish Vigenère ciphertext from other cipher types:
- Letters only, with preserved word boundaries. Like Caesar, Vigenère traditionally encrypts only alphabetic characters, leaving spaces and punctuation intact. Word lengths match the original plaintext.
- Flattened but not uniform letter frequencies. In a Caesar cipher, the frequency distribution looks like English but shifted. In Vigenère ciphertext, the distribution is significantly flatter — no single letter dominates — but it is not completely uniform either (which would suggest a one-time pad or random text).
- Index of Coincidence between 0.04 and 0.05. The IC of Vigenère ciphertext typically falls between the English value (~0.067) and the random value (~0.038), depending on key length. An IC in this intermediate range is a strong indicator of polyalphabetic substitution.
- Repeated sequences at regular intervals. If you spot identical 3+ letter sequences appearing at distances that share a common factor, the text is very likely Vigenère-encrypted (this is the basis of Kasiski analysis).
The Cipher Identifier tool on this site uses these characteristics to automatically detect Vigenère encryption and estimate the key length.
Vigenère Cipher in Python, Java & JavaScript
Implementing the Vigenère cipher is a common exercise in cryptography courses because the core math is only a few lines. These snippets encrypt A–Z letters, preserve case, and pass non-alphabet characters through unchanged.
Python
def vigenere_encrypt(text: str, key: str) -> str:
key = key.upper()
out, j = [], 0
for ch in text:
if ch.isalpha():
base = 65 if ch.isupper() else 97
shift = ord(key[j % len(key)]) - 65
out.append(chr((ord(ch) - base + shift) % 26 + base))
j += 1
else:
out.append(ch)
return "".join(out)
Java
static String vigenereEncrypt(String text, String key) {
key = key.toUpperCase();
StringBuilder out = new StringBuilder();
int j = 0;
for (char ch : text.toCharArray()) {
if (Character.isLetter(ch)) {
int base = Character.isUpperCase(ch) ? 'A' : 'a';
int shift = key.charAt(j % key.length()) - 'A';
out.append((char) ((ch - base + shift) % 26 + base));
j++;
} else {
out.append(ch);
}
}
return out.toString();
}
JavaScript
function vigenereEncrypt(text, key) {
key = key.toUpperCase();
let out = "", j = 0;
for (const ch of text) {
if (/[a-zA-Z]/.test(ch)) {
const base = ch >= "a" ? 97 : 65;
const shift = key.charCodeAt(j % key.length) - 65;
out += String.fromCharCode((ch.charCodeAt(0) - base + shift) % 26 + base);
j++;
} else {
out += ch;
}
}
return out;
}
To decrypt, subtract the shift instead of adding it: (ord(ch) - base - shift + 26) % 26 + base.
How to Pronounce "Vigenère"
The cipher is named after Blaise de Vigenère (1523–1596), a French diplomat and cryptographer. The English pronunciation is /ˌviːʒəˈnɛər/ — roughly "vee-zhuh-NAIR", rhyming with "air". The stress falls on the last syllable, and the middle g makes a soft zh sound as in "measure".
The written form carries a grave accent over the second e (è). The accent is often omitted in casual writing and search queries — both "Vigenère cipher" and "Vigenere cipher" refer to the same cipher — but the accented form is the correct spelling.
Where You'll Encounter the Vigenère Cipher
Despite being centuries old, the Vigenère cipher appears frequently in modern contexts:
- CTF competitions. Cybersecurity Capture The Flag challenges routinely use Vigenère encryption at intermediate difficulty levels. Competitors must identify the cipher type, determine the key length, and recover the key to obtain the flag.
- Escape rooms and puzzle hunts. Vigenère is a popular choice for multi-step puzzles because it requires both a key and ciphertext, allowing puzzle designers to hide the keyword as a separate clue.
- Cryptography courses. The Vigenère cipher is the standard example used to teach polyalphabetic substitution, key management, Kasiski analysis, and the Index of Coincidence in university-level cryptography and information security courses.
- Pop culture. The Vigenère cipher has appeared in the TV series Gravity Falls, the video game Destiny 2, and numerous detective novels. The animated show Gravity Falls famously used Vigenère-encrypted messages in its end credits, with the keyword hidden in each episode.
- Historical reenactment. Civil War enthusiasts and educational programs use replica Confederate cipher disks to demonstrate period-accurate encryption techniques.
Related Polyalphabetic Ciphers
The Vigenère cipher is part of a family of polyalphabetic systems that evolved from the same core idea:
- Beaufort Cipher — A reciprocal variant where the key letter is subtracted from a fixed position rather than added. Beaufort encryption and decryption use the same operation.
- Autokey Cipher — Vigenère's own invention: the key starts with a primer and then appends the plaintext itself, eliminating the repeating-key weakness.
- Gronsfeld Cipher — A Vigenère variant that restricts the key to digits (0–9), reducing the per-position keyspace from 26 to 10.
- Running Key Cipher — Uses a long passage of text (e.g., a book page) as the key, approaching one-time pad security without requiring a truly random key.
- Trithemius Cipher — The predecessor that shifts each letter progressively (A=0, B=1, C=2, …) without a secret key. Bellaso's innovation was replacing this fixed progression with a secret keyword.
- Porta Cipher — A reciprocal digraphic cipher using 13 alphabets, designed as a self-inverse system.
- Quagmire Cipher — A family of four variants that combine keyword-mixed alphabets with Vigenère-style polyalphabetic shifting.
- Alberti Cipher — The first polyalphabetic cipher, invented by Leon Battista Alberti in the 1460s using a rotating cipher disk. Alberti's concept of changing alphabets during encryption was the precursor to all subsequent polyalphabetic systems, including Bellaso's keyword method.
The evolution from Alberti's cipher disk (1460s) → Trithemius's progressive shift (1508) → Bellaso's keyword method (1553) → Vigenère's autokey system (1586) represents one of the most important development arcs in the history of cryptography, each step addressing a weakness of the previous design.
Further Reading
Explore Vigenère cipher history, cryptanalysis techniques, and code implementations:
- Breaking the Vigenère Cipher: Kasiski Examination & Index of Coincidence — Step-by-step guide to cracking Vigenère encryption without the key
- Caesar vs Vigenère Cipher: Complete Security Comparison — Understand the key differences between monoalphabetic and polyalphabetic substitution