Vigenere cipher guide

How to Encrypt and Decrypt With the Vigenère Cipher

To encrypt a message with the traditional Vigenère cipher, you need a plaintext message and a key. The key is repeated across the message, and each plaintext letter is shifted according to the corresponding key letter. To decrypt the result, you use the same key and reverse those shifts.

For example, with the plaintext HELLO and the key KEY, the key is aligned with the message as follows:

Plaintext: H E L L O Key: K E Y K E

The resulting ciphertext is:

RIJVS

This article shows the complete process for both directions, including how to align the key, perform the calculations, use the Vigenère square, handle spaces and punctuation, check your result, and avoid the most common mistakes.

If you already have a message and key, you can also use the Vigenère Cipher Encoder and Decoder on the homepage.

What you need before starting

For ordinary Vigenère encryption, you need two things:

  1. the plaintext, which is the message you want to encrypt;
  2. the key, which determines the sequence of shifts.

For decryption, you need:

  1. the ciphertext;
  2. the same key that was used for encryption.

For example:

Plaintext: HELLO Key: KEY

After encryption:

Ciphertext: RIJVS Key: KEY

The key is required for ordinary Vigenère decryption. Knowing the ciphertext alone is a different problem because recovering the plaintext without the key involves cryptanalysis rather than direct decryption.

That distinction is important throughout this site. How to Break the Vigenère Cipher deals with the separate problem of analyzing ciphertext when the key is unknown.

How to encrypt a message

The traditional repeating-key Vigenère method follows a simple sequence.

First, write the plaintext. Then write the key underneath it, repeating the key as necessary until every alphabetic position has a corresponding key letter. Finally, combine each plaintext letter with its key letter to produce the ciphertext. This repeating-key arrangement is the standard keyword method described in classical Vigenère treatments.

Suppose the message is:

HELLO

and the key is:

KEY

The key is shorter than the message, so it repeats:

Plaintext: H E L L O Key: K E Y K E

Each column is then encrypted separately:

H + K E + E L + Y L + K O + E

The resulting ciphertext is:

RIJVS

The key does not get restarted because the plaintext contains another word. Its position advances according to the characters being processed.

Convert the letters to numbers

The easiest way to calculate Vigenère encryption is to assign each letter a value from 0 to 25:

A = 0 B = 1 C = 2 D = 3 E = 4 F = 5 G = 6 H = 7 I = 8 J = 9 K = 10 L = 11 M = 12 N = 13 O = 14 P = 15 Q = 16 R = 17 S = 18 T = 19 U = 20 V = 21 W = 22 X = 23 Y = 24 Z = 25

The encryption formula is:

C = (P + K) mod 26

P represents the plaintext value, K represents the key value, and C represents the ciphertext value.

For H with key K:

H = 7 K = 10 7 + 10 = 17 17 = R So: H + K = R

The same calculation is performed for every position.

Encrypting HELLO with the key KEY

Let’s work through the complete example.

The plaintext is:

HELLO

The key is:

KEY

Because the key has three letters and the message has five, repeat the key:

Plaintext: H E L L O Key: K E Y K E

Now calculate each position.

First pair:

H = 7 K = 10 7 + 10 = 17 17 = R

Second pair:

E = 4 E = 4 4 + 4 = 8 8 = I

Third pair:

L = 11 Y = 24 11 + 24 = 35 35 mod 26 = 9 9 = J

Fourth pair:

L = 11 K = 10 11 + 10 = 21 21 = V

Fifth pair:

O = 14 E = 4 14 + 4 = 18 18 = S

The complete result is:

Plaintext: H E L L O Key: K E Y K E Ciphertext: R I J V S

Therefore:

HELLO → RIJVS

when the key is KEY. This example also shows why the key must be repeated. The fourth plaintext letter uses K because the three-letter key has completed one cycle:

K E Y K E

What happens when the message is longer than the key?

The key simply continues from its beginning.

Suppose the plaintext is:

THISISALONGMESSAGE

and the key is:

KEY

The alignment becomes:

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 therefore follows this repeating sequence:

KEYKEYKEYKEYKEYKEY…

The key is not stretched or modified. Its letters are reused in the same order.

This repeated alignment is one of the defining properties of the traditional keyword Vigenère method.

Encrypting a message with spaces

Spaces require a small but important implementation decision. A common alphabetic Vigenère implementation preserves spaces for readability but does not use them as alphabetic key positions. Other implementations may remove spaces before processing or define a broader character set.

For example, a tool may conceptually process:

ATTACK AT DAWN as: ATTACKATDAWN

while displaying the result with spaces retained.

The important point is that the space does not necessarily consume a character from the key.

This matters when comparing results from different Vigenère implementations. Two tools can use the same underlying alphabetic cipher while producing different-looking output if they follow different rules for non-alphabetic characters.

For any particular implementation, check whether spaces and punctuation are skipped, removed, preserved, or included in the character set.

Encrypting punctuation and numbers

The traditional Vigenère cipher operates on an alphabet, normally the 26 letters A-Z. Punctuation and numbers are therefore not automatically part of the mathematical cipher unless a particular implementation explicitly defines them as part of its character set.

For example:

Meet at 8!

contains letters, a space, a number, and punctuation.

An alphabetic implementation may encrypt only the letters:

MEETAT

while leaving:

8!

unchanged.

Another implementation may reject unsupported characters or use a broader character set. There is no universal requirement that every Vigenère program handle non-alphabetic characters in exactly the same way. Implementations can define their own character-processing rules.

How to use the Vigenère square for encryption

You do not need to calculate numerical values manually. The same encryption can be performed with a Vigenère square, also called a tabula recta.

The table contains shifted versions of the alphabet. You select the appropriate row and column according to the table’s convention and read the intersection.

For example:

Plaintext: H Key: K

Using the standard Vigenère relationship:

H + K = R

The table gives the same result as the numerical calculation:

H = 7 K = 10 7 + 10 = 17 17 = R

The table is simply a visual representation of the same modular arithmetic. A standard Vigenère reference describes encryption as selecting the plaintext row and key column and taking the letter at their intersection.

The numerical method is generally easier when working with software or checking a large number of characters. The table can be convenient for manual work.

How to decrypt a Vigenère ciphertext

Decryption reverses encryption. You start with the ciphertext and the original key.

The decryption formula is:

P = (C – K) mod 26

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

Using our previous example:

Ciphertext: R I J V S Key: K E Y K E

The first pair is:

R = 17 K = 10 17 – 10 = 7 7 = H

So the first plaintext letter is H.

The second pair:

I = 8 E = 4 8 – 4 = 4 4 = E

The third:

J = 9 Y = 24 9 – 24 = -15 Because the alphabet wraps around, add 26: -15 + 26 = 11 11 = L

The fourth:

V = 21 K = 10 21 – 10 = 11 11 = L

The fifth:

S = 18 E = 4 18 – 4 = 14 14 = O

The recovered plaintext is:

HELLO

Therefore:

RIJVS → HELLO

using the key KEY.

Why negative results are not a problem

Subtraction can produce a negative number during decryption.

For example:

A – D

becomes:

0 – 3 = -3

There is no negative letter position in the alphabet, so the result wraps around:

-3 mod 26 = 23 And: 23 = X

Therefore:

A – D = X

The alphabet is treated cyclically for both encryption and decryption. You do not need a special decryption rule for negative results. The modulo operation handles the wraparound.

Decrypting with the Vigenère square

The table can also be used in reverse.

Suppose the ciphertext letter is:

R

and the corresponding key letter is:

K

Find the row associated with the key letter K. Then locate R within that row. The corresponding column identifies the plaintext letter:

H

So:

R – K = H

The same process is repeated for every ciphertext letter. This is the inverse of the encryption lookup. The exact visual procedure depends on the orientation of the Vigenère table being used, but the underlying operation remains the same modular subtraction.

A full encryption and decryption example

Consider the message:

MEETME

with the key:

CODE

The key is shorter than the message, so repeat it:

Plaintext: M E E T M E Key: C O D E C O

Now calculate each position.

First:

M = 12 C = 2 12 + 2 = 14 14 = O

Second:

E = 4 O = 14 4 + 14 = 18 18 = S

Third:

E = 4 D = 3 4 + 3 = 7 7 = H

Fourth:

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

Fifth:

M = 12 C = 2 12 + 2 = 14 14 = O

Sixth:

E = 4 O = 14 4 + 14 = 18 18 = S

The ciphertext is:

OSHXOS

Now decrypt it with the same key:

Ciphertext: O S H X O S Key: C O D E C O

Reverse each operation:

O – C = M S – O = E H – D = E X – E = T O – C = M S – O = E

The original message returns:

MEETME

This illustrates the complete relationship:

Plaintext + Key → Ciphertext Ciphertext – Key → Plaintext

The two operations are inverses of one another.

How to choose a Vigenère key

For a historical or educational example, the key can be an ordinary word:

LEMON KEY CIPHER

The key determines the repeating sequence of shifts. However, choosing a memorable word does not make the traditional Vigenère cipher suitable for modern security.

A short dictionary word can be guessed, and the repeating-key construction creates structural information that can be investigated through classical cryptanalysis.

The key should therefore be thought about differently depending on the purpose.

For a classroom example:

KEY = LEMON

is perfectly reasonable.

For a historical puzzle:

KEY = CODES

may be appropriate.

For protecting sensitive modern information, the traditional Vigenère cipher should not be used.

The cryptanalytic limitations of the repeating-key system are covered in How to Break the Vigenère Cipher .

Common mistakes when encrypting

Most incorrect Vigenère results come from a small number of alignment or arithmetic errors.

Repeating the wrong key position

If the key is:

KEY

the sequence must be:

K E Y K E Y K E Y…

It should not restart at every word unless the implementation specifically defines that behavior.

Using the wrong alphabet values

The conventional mapping is:

A = 0 B = 1 … Z = 25

Using A = 1 instead changes every calculation.

Forgetting modulo 26

If an addition produces 30, the result cannot simply be converted directly to a letter. It must wrap around:

30 mod 26 = 4

which gives:

E

Subtracting in the wrong direction during decryption

Encryption uses:

P + K

Decryption uses:

C – K

Reversing that order changes the result.

Letting spaces consume key positions without checking the convention

If the implementation skips spaces, then:

HELLO WORLD

does not use a key character for the space.

If the implementation treats every character differently, the alignment can change. Always follow the convention of the cipher implementation you are using.

How to check an encrypted result

A quick way to verify a Vigenère calculation is to decrypt the ciphertext using the same key.

For example:

Plaintext: HELLO Key: KEY Ciphertext: RIJVS

Now decrypt:

RIJVS + KEY → HELLO

If the original plaintext does not return, something is wrong with one of the following:

  • the key;
  • the key alignment;
  • the alphabet convention;
  • the treatment of spaces or punctuation;
  • the arithmetic; or
  • the implementation’s rules.

This round-trip check is particularly useful when implementing the cipher in software.

A correct implementation should satisfy the basic relationship:

Decrypt(Encrypt(plaintext, key), key) = plaintext

for the characters and conventions supported by that implementation.

Encrypting and decrypting with an online Vigenère tool

If you do not need to perform the calculations by hand, an online Vigenère tool can handle the repetitive work.

For encryption, enter:

Plaintext + Key

and select the encryption operation. The tool applies the key across the message and returns the ciphertext.

For decryption, enter:

Ciphertext + Key

and select the decryption operation. The tool reverses the shifts and returns the plaintext.

Before comparing its output with a manually calculated result, check how the tool handles:

  • spaces;
  • punctuation;
  • numbers;
  • capitalization;
  • key repetition; and
  • unsupported characters.

This matters because the Vigenère algorithm defines the alphabetic transformation, while an online implementation must also decide how to handle characters outside that alphabet.

What if you do not know the key?

This is where ordinary decryption ends and cryptanalysis begins.

If you have:

Ciphertext + Key

you can decrypt directly.

If you have:

Ciphertext

but do not know the key, you cannot simply apply the decryption formula because the key values are missing. You need to investigate the ciphertext to recover information about the key.

For the traditional repeating-key Vigenère cipher, classical techniques include estimating the key length and then analyzing the resulting letter streams. The Kasiski examination and Index of Coincidence are among the established approaches used for this purpose.

That is a different task from the ordinary encryption and decryption procedure described in this article.

For the full process, see How to Break the Vigenère Cipher .

Encryption and decryption at a glance

The complete workflow can be reduced to four steps.

Encryption

  1. Start with plaintext.
  2. Repeat the key across the message.
  3. Add each plaintext value to its key value modulo 26.
  4. Convert the results back to letters.

Formula:

C = (P + K) mod 26

Decryption

  1. Start with ciphertext.
  2. Repeat the same key across the message.
  3. Subtract each key value from its ciphertext value modulo 26.
  4. Convert the results back to letters.

Formula:

P = (C – K) mod 26

The same key is used in both directions. The difference is the arithmetic operation.

The difference between using a known key and breaking the cipher

There are three separate situations worth keeping apart.

Encrypting a message

You know the plaintext and the key.

Plaintext + Key → Ciphertext

Decrypting a message

You know the ciphertext and the key.

Ciphertext + Key → Plaintext

Breaking a message

You know the ciphertext but are trying to determine the key or plaintext.

Ciphertext → Cryptanalysis → Candidate key → Plaintext

The first two are direct Vigenère operations. The third involves analysis of the cipher’s structure.

Keeping these tasks separate prevents a common misunderstanding: an online “Vigenère decoder” that requires a key is performing ordinary decryption, while recovering plaintext from ciphertext without the key is a cryptanalysis problem.

Continue learning about the Vigenère cipher

If you want to understand the mechanism behind these calculations, read How Does the Vigenère Cipher Work?

If you have ciphertext but do not know the key, continue with How to Break the Vigenère Cipher to learn how repeating-key structure can be analyzed.

If you want to understand how the system developed and why it became associated with Vigenère, see History of the Vigenère Cipher .

If you simply want to perform an encryption or decryption operation, use the Vigenère Cipher Decoder and Encoder on the homepage.

Similar Posts

Leave a Reply

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