Vigenere cipher guide

How Does the Vigenère Cipher Work?

The Vigenère cipher works by combining each plaintext letter with a corresponding letter from a key. Each key letter determines how far the plaintext letter is shifted through the alphabet. When the key is shorter than the message, the traditional repeating-key Vigenère cipher cycles back to the beginning of the key and continues.

That sounds similar to a Caesar cipher, and mechanically it is. The difference is that a Caesar cipher keeps the same shift throughout the message, while Vigenère changes the shift according to the key.

For example, if the key is LEMON, the first plaintext letter is shifted according to L, the second according to E, the third according to M, and so on. When N has been used, the key starts again with L.

This article follows that process from beginning to end, including the Vigenère square, the mathematical formula, key alignment, encryption, decryption, and the treatment of spaces and punctuation.

If you simply want to run the operation yourself, you can use the Vigenère Cipher Decoder and Encoder on the homepage.

The three things Vigenère needs

A standard Vigenère operation involves three basic elements:

Plaintext: the original message being encrypted.

Key: the word or sequence of letters controlling the shifts.

Ciphertext: the result produced by encryption.

Suppose the plaintext is:

ATTACK

and the key is:

LEMONL

Each plaintext character is paired with one key character:

Plaintext: A T T A C K Key: L E M O N L

The cipher then processes those pairs individually.

The first operation is therefore not performed on the entire word ATTACK at once. It is six separate letter operations:

A + L T + E T + M A + O C + N K + L

The resulting letters form the ciphertext.

This pair-by-pair structure is important because the key is not simply a password that gets checked against the message. It actively determines the transformation applied at each position.

How the key controls the shift

The alphabet can be treated as a sequence of numbers:

A = 0 B = 1 C = 2 D = 3 E = 4 … Y = 24 Z = 25

This gives every letter a numerical shift value.

The key LEMON, for example, becomes:

L = 11 E = 4 M = 12 O = 14 N = 13

When a plaintext letter is paired with a key letter, the two numerical values are added.

For example:

A = 0 L = 11 0 + 11 = 11 11 = L

So A encrypted with L becomes L.

Another position might contain:

T = 19 E = 4 19 + 4 = 23 23 = X

So T encrypted with E becomes X.

The operation is repeated for every position.

The reason the alphabet can wrap around is that the calculation is performed modulo 26. Once the numerical result reaches 26, counting starts again from 0. The standard mathematical description is:

C = (P + K) mod 26

where P is the plaintext value, K is the key value, and C is the ciphertext value.

Why modulo 26 is necessary

Consider a plaintext letter near the end of the alphabet.

Suppose we encrypt:

Y

using the key letter:

D

The numerical values are:

Y = 24 D = 3

Adding them gives:

24 + 3 = 27

But there is no letter numbered 27 in a 26-letter alphabet.

Modulo 26 solves the problem:

27 mod 26 = 1 And: 1 = B

Therefore:

Y + D = B

The same wraparound happens whenever an addition passes Z.

For example:

Z + A = Z Z + B = A Z + C = B

This is not a special exception added to the cipher. It is simply the result of performing the arithmetic in a 26-character alphabet.

The Vigenère square and tabula recta

The Vigenère square, also known as the tabula recta, is a visual representation of the shifted alphabets used by the cipher.

It consists of rows containing shifted versions of the alphabet. Each row corresponds to a particular key letter.

For encryption, the plaintext letter and key letter are used to locate the appropriate position in the table.

For example, with plaintext H and key L, the relevant shifted alphabet produces S.

Numerically:

H = 7 L = 11 7 + 11 = 18 18 = S

The table and the formula therefore produce the same result.

The table is simply a visual way of carrying out the addition. The U.S. Naval Academy’s instructional material presents the same row-and-column approach for Vigenère encryption and decryption.

How the repeating key is aligned

A key is often much shorter than the message.

Suppose the plaintext is:

THISISALONGMESSAGE

and the key is:

KEY

The traditional repeating-key method extends the key across the message:

Plaintext: T H I S I S A L O N G M E S S A G E Key: K E Y K E Y K E Y K E Y K E Y K E Y K

The key does not change after one use. It cycles:

K E Y K E Y K E Y K E Y K E Y …

This creates the repeating keystream used by the cipher.

Educational and university treatments of the Vigenère cipher describe the same process: the keyword is written repeatedly beneath the plaintext so that each plaintext position has a corresponding key letter.

What happens when spaces are present?

There is an implementation detail that matters when using online Vigenère tools: different implementations can treat non-letter characters differently.

A traditional presentation may remove spaces and punctuation before encryption and restore them afterward. Other implementations preserve spaces and punctuation in the displayed message while advancing the key only when an alphabetic character is processed.

The exact convention depends on the implementation.

For example, a tool might conceptually process:

ATTACK AT DAWN as: ATTACKATDAWN

while displaying the result with the spaces retained.

That means the space itself does not necessarily consume a character from the key.

This distinction matters when comparing results from different Vigenère implementations. Two tools can use the same underlying cipher but produce apparently different results if they use different rules for non-alphabetic characters.

For any particular implementation, the safest approach is to understand whether spaces and punctuation are skipped, removed, preserved, or treated as part of the cipher alphabet.

A complete encryption example

Now consider the complete example:

Plaintext: ATTACK Key: LEMONL

Convert the letters into numerical values:

Plaintext: A = 0 T = 19 T = 19 A = 0 C = 2 K = 10 Key: L = 11 E = 4 M = 12 O = 14 N = 13 L = 11

Apply the encryption formula to each pair:

A + L = 0 + 11 = 11 = L T + E = 19 + 4 = 23 = X T + M = 19 + 12 = 31 mod 26 = 5 = F A + O = 0 + 14 = 14 = O C + N = 2 + 13 = 15 = P K + L = 10 + 11 = 21 = V

The ciphertext is:

LXFOPV

The complete transformation can therefore be represented as:

Plaintext: A T T A C K Key: L E M O N L Ciphertext: L X F O P V

Every ciphertext character comes from one plaintext-key pair.

That is the encryption process in its basic form.

How Vigenère decryption works

Decryption reverses the operation.

During encryption, the key value is added to the plaintext:

C = (P + K) mod 26

To recover the plaintext, subtract the key:

P = (C – K) mod 26

The same key is required to reverse the transformation.

Using the previous ciphertext:

Ciphertext: L X F O P V Key: L E M O N L

we subtract the corresponding key values:

L – L = A X – E = T F – M = T O – O = A P – N = C V – L = K

The original message returns:

ATTACK

Vigenère is therefore a symmetric-key cipher: the communicating parties use the same shared key for the encryption and decryption process. The U.S. Naval Academy’s instructional material presents Vigenère within its treatment of symmetric encryption and demonstrates both directions using the same key.

If you want to work through the practical process with your own plaintext and key, see How to Encrypt and Decrypt With the Vigenère Cipher .

Decrypting with the Vigenère square

The same reversal can be performed using the Vigenère table.

Suppose you have:

Ciphertext: L Key: L

Using the common table orientation, find the row corresponding to L. Then locate the ciphertext letter L within that row. The column heading identifies the plaintext letter.

That gives:

L – L = A

For another example:

Ciphertext: X Key: E

Find X in row E. The corresponding column is T.

Therefore:

X – E = T

The table is effectively performing the subtraction for you.

This is why a Vigenère table can be used in both directions even though encryption and decryption use different formulas.

Why the same plaintext letter can produce different ciphertext letters

One of the important consequences of the Vigenère key is that a plaintext letter does not have one permanent ciphertext equivalent.

Suppose the plaintext contains several occurrences of A.

If the corresponding key letters are:

A D L

then the same plaintext letter can become:

A + A = A A + D = D A + L = L

The plaintext has not changed.

The key position has.

That means a repeated plaintext letter can produce different ciphertext letters when different key letters are aligned with it.

This is one reason Vigenère behaves differently from a monoalphabetic substitution cipher. A monoalphabetic cipher establishes one fixed mapping, such as:

A → Q

and every occurrence of A receives Q.

Vigenère instead makes the mapping dependent on the key position.

What the key length changes

The length of the key determines how frequently the sequence of shifts repeats.

A three-letter key produces a pattern like:

K E Y K E Y K E Y …

A five-letter key produces:

L E M O N L E M O N …

A ten-letter key repeats only after ten alphabetic positions.

This does not simply mean that a longer keyword is automatically equivalent to stronger encryption.

For the traditional Vigenère system, what matters is that the key stream eventually repeats. That repetition creates a period in the cipher.

If the key has length five, positions separated by five letters use the same key position. Those positions therefore receive the same Caesar-style shift.

This periodic structure is one of the properties later exploited by classical cryptanalysis.

The detailed attack methods belong in How to Break the Vigenère Cipher , rather than being repeated here.

What happens when encryption wraps around Z?

Because the alphabet is treated cyclically, encryption can move from the end of the alphabet back to its beginning.

Suppose:

X + F

Using numerical values:

X = 23 F = 5 23 + 5 = 28

Apply modulo 26:

28 mod 26 = 2 And: 2 = C

Therefore:

X + F = C

The alphabet effectively behaves like a circle:

… X → Y → Z → A → B → C …

The same principle applies in reverse during decryption.

If subtraction produces a negative number, modulo 26 wraps the result back into the alphabet.

For example:

C – F

becomes:

2 – 5 = -3

Wrapping around the 26-letter alphabet gives:

23 = X So: C – F = X

This wraparound is why modular arithmetic is useful: the operation always returns a valid alphabet position.

What a Vigenère decoder actually does

When you enter ciphertext and a key into a Vigenère decoder, the tool is essentially repeating the same process described above for every encrypted letter.

Conceptually, it performs:

1. Read a ciphertext letter. 2. Identify the corresponding key letter. 3. Convert both letters to numerical values. 4. Subtract the key value from the ciphertext value. 5. Apply modulo 26. 6. Convert the resulting number back into a letter. 7. Move to the next position.

If the key has reached its final character, the decoder cycles back to the first key character.

The process continues until all applicable ciphertext characters have been processed.

The result is the recovered plaintext.

There is no separate “Vigenère decoding trick” hidden inside the tool. For a known key, the decoder is implementing the inverse mathematical operation of the encoder.

This distinction becomes important when the key is unknown. Recovering plaintext without knowing the key is no longer ordinary decryption. It becomes a cryptanalysis problem.

What a Vigenère encoder actually does

The encoder performs the opposite operation:

1. Read a plaintext letter. 2. Identify the corresponding key letter. 3. Convert both letters to numerical values. 4. Add the two values. 5. Apply modulo 26. 6. Convert the result back into a letter. 7. Move to the next position.

For a repeating key, the key position cycles back to the beginning whenever the end of the key is reached.

In mathematical form:

C = (P + K) mod 26

In practical terms:

Plaintext letter + key letter = ciphertext letter

The table-based method and the numerical method are two representations of the same operation.

Why the Vigenère square is still useful

Once the mathematical formula is understood, the Vigenère square may seem unnecessary.

For software, it largely is.

For learning, however, the table makes the relationship between the key and the substitution visible.

You can see all 26 Caesar-style alphabets at once. Moving from one key row to another visibly changes the substitution being applied.

It also makes manual encryption possible without calculating numerical values for every character.

For example, if you know:

Plaintext = H Key = L

you can locate the H column and L row and read the intersection.

The result is:

S

The numerical calculation is:

7 + 11 = 18 = S

The two methods are equivalent.

The table is therefore best understood as a visual representation of the arithmetic, not as a separate algorithm.

Vigenère encryption, decryption, and cryptanalysis are different tasks

These three terms are often mixed together, but they describe different operations.

Encryption starts with plaintext and a key:

Plaintext + Key → Ciphertext

Decryption starts with ciphertext and the known key:

Ciphertext + Key → Plaintext

Cryptanalysis starts with ciphertext when some important information, usually the key, is unknown:

Ciphertext → Analysis → Candidate key → Plaintext

The first two are direct transformations.

The third is an investigation.

This distinction is especially important for the traditional Vigenère cipher because the repeating key creates patterns that can sometimes be analyzed without being given the original key.

Our How to Break the Vigenère Cipher article covers that problem separately, including the methods used to estimate the key length and analyze the resulting ciphertext streams. Classical treatments specifically describe Kasiski and Friedman-style methods for determining the length of a repeating keyword.

Is Vigenère still secure?

The mechanics of Vigenère are mathematically well-defined for the operation it specifies, but that does not make the traditional cipher suitable for modern security.

The weakness is not that the addition or subtraction formula is incorrectly implemented.

It comes from the structure of the repeating key.

Once the key repeats, positions separated by the key length use the same shift. With enough ciphertext, that periodic structure can provide information that classical cryptanalysis can exploit. Kasiski-style analysis and statistical approaches such as the Index of Coincidence are designed around this property.

For that reason, the traditional Vigenère cipher is best treated as a classical cryptographic system for education, historical study, puzzles, and experimentation, not as modern protection for sensitive information.

If your goal is to understand why that weakness exists, the next article to read is How to Break the Vigenère Cipher .

A complete mental model of Vigenère

The mechanism can be summarized as a sequence of changing Caesar shifts.

The key supplies the shifts.

The plaintext supplies the letters being shifted.

The alphabet wraps around after Z.

The key repeats when the message is longer than the key.

Encryption adds the two values.

Decryption subtracts the key value.

The Vigenère square provides a visual way to perform those operations.

In compact form:

KEY ↓ Plaintext → [Shift] → Ciphertext ↑ key-dependent alphabet

Or mathematically:

Encryption: C = (P + K) mod 26 Decryption: P = (C – K) mod 26

These relationships define the standard repeating-key Vigenère operation: the key supplies the shifts, modular arithmetic performs the transformation, and the inverse operation recovers the plaintext.

Continue learning about the Vigenère cipher

If you want to apply the process immediately, use the Vigenère Cipher Decoder and Encoder on the homepage.

If you already know the key and want practical examples of both directions, continue with How to Encrypt and Decrypt With the Vigenère Cipher .

If you have ciphertext but no key, read How to Break the Vigenère Cipher to understand how repeating-key structure can be investigated.

And if you want to understand where this system came from and why it carries the Vigenère name, read History of the Vigenère Cipher .

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *