Vigenère Cipher in Cryptography: Polyalphabetic Encryption and Decryption Guide

Vigenère Cipher in Cryptography

I remember the first time I understood why the Vigenère cipher was called “le chiffre indéchiffrable” — the indecipherable cipher — for nearly three centuries. After spending time with the monoalphabetic substitution cipher and seeing how easily frequency analysis tears it apart, the Vigenère cipher felt like a genuine leap forward. It doesn’t just substitute one letter for another; it shifts the entire substitution rule depending on where you are in the message. In this guide, I want to take you through exactly how it works, the mathematics behind it, how to encrypt and decrypt by hand, and eventually, how it was finally broken.

What Is the Vigenère Cipher?

The Vigenère cipher is a polyalphabetic substitution cipher, meaning it uses multiple substitution alphabets rather than a single fixed one. It was named after Blaise de Vigenère, a 16th-century French diplomat, although the technique was actually first described by Giovan Battista Bellaso a few decades earlier. Vigenère’s name stuck because a later, related cipher was misattributed to him.

The core idea is simple but powerful: instead of shifting every letter of the plaintext by the same fixed amount (like the Caesar cipher does), the Vigenère cipher shifts each letter by an amount that depends on a repeating keyword. Because the shift changes from letter to letter, the same plaintext letter can be encrypted into different ciphertext letters depending on its position — which is exactly what defeats simple frequency analysis.

Mathematical Foundation

I find it easiest to describe the Vigenère cipher using modular arithmetic, treating each letter as a number from 0 (A) to 25 (Z).

Let the plaintext be a sequence of letters:

$$ P = p_1, p_2, p_3, \dots, p_n $$

Let the keyword be a sequence of letters:

$$ K = k_1, k_2, \dots, k_m $$

Since the keyword is usually shorter than the plaintext, it’s repeated cyclically to match the plaintext length. I define the extended key sequence as:

$$ k_i’ = k_{(i-1) \bmod m + 1} $$

Encryption Formula

Each ciphertext letter is computed as:

$$ c_i = (p_i + k_i’) \bmod 26 $$

Decryption Formula

Decryption reverses the shift:

$$ p_i = (c_i – k_i’) \bmod 26 $$

Here, addition and subtraction are performed modulo 26 because there are 26 letters in the English alphabet, and modular arithmetic naturally “wraps around” from Z back to A.

Why This Defeats Simple Frequency Analysis

In a monoalphabetic cipher, the substitution function $f$ is fixed for the entire message. In the Vigenère cipher, the effective substitution function changes with position:

$$ f_i(p_i) = (p_i + k_i’) \bmod 26 $$

Since $k_i’$ cycles through $m$ different values, there are effectively $m$ different Caesar-shift alphabets in play, each used at different positions throughout the message. This means the same plaintext letter, appearing at different positions, is very likely to be encrypted to different ciphertext letters — smoothing out the frequency distribution that would otherwise give away the underlying language structure.

The Vigenère Square (Tabula Recta)

Historically, encryption was performed using a Vigenère square, a 26×26 grid where each row is a Caesar-shifted version of the alphabet.

A small excerpt of the table looks like this:

Key ↓ / Plain →ABCDE
AABCDE
BBCDEF
CCDEFG
DDEFGH
EEFGHI

To encrypt a plaintext letter, I find the column matching the plaintext letter and the row matching the current key letter; their intersection gives the ciphertext letter.

Step-by-Step Encryption Example

Let’s say I want to encrypt the plaintext ATTACKATDAWN using the keyword LEMON.

Step 1: Repeat the key to match the plaintext length.

Plaintext:  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

Step 2: Convert letters to numbers.

LetterATTACKATDAWN
Value019190210019302213
KeyLEMONLEMONLE
Value114121413114121413114

Step 3: Apply the formula $c_i = (p_i + k_i’) \bmod 26$.

Positionp + kmod 26Ciphertext
10 + 11 = 1111L
219 + 4 = 2323X
319 + 12 = 315F
40 + 14 = 1414O
52 + 13 = 1515P
610 + 11 = 2121V
70 + 4 = 44E
819 + 12 = 315F
93 + 14 = 1717R
100 + 13 = 1313N
1122 + 11 = 337H
1213 + 4 = 1717R

Resulting ciphertext:

LXFOPVEFRNHR

Step-by-Step Decryption Example

To decrypt, I reverse the process using $p_i = (c_i – k_i’) \bmod 26$.

Starting with ciphertext LXFOPVEFRNHR and the same keyword LEMON:

Positionc – kmod 26Plaintext
111 – 11 = 00A
223 – 4 = 1919T
35 – 12 = -719T
414 – 14 = 00A
515 – 13 = 22C
621 – 11 = 1010K
74 – 4 = 00A
85 – 12 = -719T
917 – 14 = 33D
1013 – 13 = 00A
117 – 11 = -422W
1217 – 4 = 1313N

This correctly recovers ATTACKATDAWN.

Implementation Example (Python)

Here’s an implementation I wrote to encrypt and decrypt using the formulas above:

def vigenere_encrypt(plaintext, key):
    plaintext = plaintext.upper().replace(" ", "")
    key = key.upper()
    ciphertext = []
    for i, char in enumerate(plaintext):
        p = ord(char) - ord('A')
        k = ord(key[i % len(key)]) - ord('A')
        c = (p + k) % 26
        ciphertext.append(chr(c + ord('A')))
    return "".join(ciphertext)

def vigenere_decrypt(ciphertext, key):
    ciphertext = ciphertext.upper().replace(" ", "")
    key = key.upper()
    plaintext = []
    for i, char in enumerate(ciphertext):
        c = ord(char) - ord('A')
        k = ord(key[i % len(key)]) - ord('A')
        p = (c - k) % 26
        plaintext.append(chr(p + ord('A')))
    return "".join(plaintext)

message = "ATTACKATDAWN"
keyword = "LEMON"

encrypted = vigenere_encrypt(message, keyword)
decrypted = vigenere_decrypt(encrypted, keyword)

print("Encrypted:", encrypted)
print("Decrypted:", decrypted)

Running this reproduces the same LXFOPVEFRNHR ciphertext and correctly decrypts it back to ATTACKATDAWN.

Internal Working: Why It Resisted Attack for So Long

The internal mechanics of the Vigenère cipher combine a repeating key stream with modular addition. Unlike a monoalphabetic cipher’s static lookup, the Vigenère cipher effectively layers $m$ separate Caesar ciphers on top of each other, cycling through them based on position. This “smearing” of substitution rules across multiple alphabets is what flattens the letter-frequency distribution in the ciphertext, which is exactly why it stumped cryptanalysts for so long after its invention.

Security Analysis and Cryptanalysis

The Core Weakness: Key Repetition

Despite its reputation, the Vigenère cipher has a structural weakness: the key repeats. If the key length is $m$, then every $m$-th letter of the plaintext is encrypted using the same Caesar shift. This means the ciphertext is really $m$ interleaved monoalphabetic ciphers, each of which is individually vulnerable to frequency analysis — once you know or can estimate $m$.

Kasiski Examination

In 1863, Friedrich Kasiski published a method for determining the key length by looking for repeated sequences of letters in the ciphertext. If the same substring of plaintext happens to align with the same portion of the key at two different points in the message, it produces an identical ciphertext substring. By measuring the distance between repeated ciphertext substrings and finding common factors of those distances, I can estimate the key length $m$.

Friedman’s Index of Coincidence

William Friedman later developed a more rigorous statistical approach using the index of coincidence (IC), defined as:

$$ IC = \frac{\sum_{i=0}^{25} n_i (n_i – 1)}{N(N-1)} $$

where $n_i$ is the number of occurrences of the $i$-th letter in the ciphertext and $N$ is the total number of letters. A ciphertext encrypted with a longer effective key length will have an IC closer to that of random text ($\approx 0.038$ for English’s 26-letter alphabet), while a shorter key length produces an IC closer to that of natural language (around $0.065$ for English). By testing different candidate key lengths and measuring the IC of each resulting subsequence, I can estimate the most probable key length.

Once the Key Length Is Known

After determining the key length $m$, the ciphertext can be split into $m$ separate groups, each of which was encrypted with a single, fixed Caesar shift. At that point, standard frequency analysis (as used against monoalphabetic ciphers) can be applied independently to each group, recovering each character of the key one at a time.

Vulnerabilities and Countermeasures

The Vigenère cipher’s core vulnerability is key reuse over a length shorter than the message. Two historical countermeasures attempted to address this:

Even with these countermeasures, the Vigenère family of ciphers is considered cryptographically broken by modern standards and unsuitable for protecting sensitive information.

Practical Examples and Real-World Applications

While it’s no longer used for serious data protection, I still see the Vigenère cipher show up in a few practical contexts:

Professional Security Workflow Context

In a professional setting, I treat any reference to Vigenère-style encryption in production systems as a serious red flag during a security audit. If I ever came across a legacy system using this scheme to protect real data, my workflow would be:

  1. Flag it immediately as a cryptographically broken legacy algorithm.
  2. Assess exposure — how much sensitive data has been encrypted with it, and for how long.
  3. Recommend migration to a modern, vetted algorithm (such as AES-256-GCM or ChaCha20-Poly1305) implemented via a well-audited cryptographic library.
  4. Ensure any historical Vigenère-encrypted data is re-encrypted (or, if sensitive, considered potentially compromised).

Best Practices

Performance Considerations

Computationally, the Vigenère cipher is extremely lightweight — encryption and decryption are just modular addition and subtraction operations, making it fast even on very constrained hardware. This is part of why it remained attractive for so long historically, even after purely mathematical alternatives existed: it required no special equipment, just a table and a keyword.

Limitations

Common Mistakes I See People Make

Frequently Asked Questions

Why was the Vigenère cipher called “indecipherable”? For nearly 300 years after its popularization, no reliable general method existed to break it, largely because cryptanalysts hadn’t yet developed the statistical techniques (Kasiski examination, index of coincidence) needed to determine the key length.

What is the main difference between the Vigenère cipher and the Caesar cipher? The Caesar cipher uses a single, fixed shift for the entire message, making it a monoalphabetic cipher. The Vigenère cipher uses a repeating keyword to vary the shift at each position, making it polyalphabetic.

How is the Vigenère cipher actually broken? By first estimating the key length using Kasiski examination or the index of coincidence, then splitting the ciphertext into that many interleaved groups and applying standard frequency analysis to each group individually.

Is the Vigenère cipher related to the one-time pad? Yes, conceptually — the one-time pad can be viewed as an idealized Vigenère cipher where the key is truly random, exactly as long as the message, and never reused, which is what gives it perfect secrecy.

Can the Vigenère cipher be used safely today? No. It should never be used to protect real sensitive information. It’s valuable today strictly for teaching cryptographic history, statistical cryptanalysis, and the reasoning that led to modern stream ciphers.

What role does the index of coincidence play in cryptanalysis? It provides a statistical fingerprint that helps estimate the likely key length by measuring how much the letter distribution in a ciphertext (or ciphertext subsequence) resembles that of natural language versus random text.

Summary

The Vigenère cipher represents a genuine conceptual advance over monoalphabetic substitution: by cycling through multiple Caesar shifts based on a repeating keyword, it smooths out the frequency patterns that made earlier ciphers so easy to break. But its reliance on a short, repeating key ultimately became its downfall, once Kasiski examination and the index of coincidence gave cryptanalysts the statistical tools to unwind that repetition. Studying the Vigenère cipher today isn’t about using it for real protection — it’s about understanding the direct intellectual lineage from classical substitution to the one-time pad, and eventually to the stream ciphers used in modern systems.

References

Exit mobile version