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:
The resulting ciphertext is:
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:
- the plaintext, which is the message you want to encrypt;
- the key, which determines the sequence of shifts.
For decryption, you need:
- the ciphertext;
- the same key that was used for encryption.
For example:
After encryption:
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:
and the key is:
The key is shorter than the message, so it repeats:
Each column is then encrypted separately:
The resulting ciphertext is:
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:
The encryption formula is:
P represents the plaintext value, K represents the key value, and C represents the ciphertext value.
For H with key K:
The same calculation is performed for every position.
Encrypting HELLO with the key KEY
Let’s work through the complete example.
The plaintext is:
The key is:
Because the key has three letters and the message has five, repeat the key:
Now calculate each position.
First pair:
Second pair:
Third pair:
Fourth pair:
Fifth pair:
The complete result is:
Therefore:
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:
What happens when the message is longer than the key?
The key simply continues from its beginning.
Suppose the plaintext is:
and the key is:
The alignment becomes:
The key therefore follows this repeating sequence:
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:
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:
contains letters, a space, a number, and punctuation.
An alphabetic implementation may encrypt only the letters:
while leaving:
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:
Using the standard Vigenère relationship:
The table gives the same result as the numerical calculation:
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:
C is the ciphertext value, K is the key value, and P is the recovered plaintext value.
Using our previous example:
The first pair is:
So the first plaintext letter is H.
The second pair:
The third:
The fourth:
The fifth:
The recovered plaintext is:
Therefore:
using the key KEY.
Why negative results are not a problem
Subtraction can produce a negative number during decryption.
For example:
becomes:
There is no negative letter position in the alphabet, so the result wraps around:
Therefore:
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:
and the corresponding key letter is:
Find the row associated with the key letter K. Then locate R within that row. The corresponding column identifies the plaintext letter:
So:
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:
with the key:
The key is shorter than the message, so repeat it:
Now calculate each position.
First:
Second:
Third:
Fourth:
Fifth:
Sixth:
The ciphertext is:
Now decrypt it with the same key:
Reverse each operation:
The original message returns:
This illustrates the complete relationship:
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:
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:
is perfectly reasonable.
For a historical puzzle:
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:
the sequence must be:
It should not restart at every word unless the implementation specifically defines that behavior.
Using the wrong alphabet values
The conventional mapping is:
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:
which gives:
Subtracting in the wrong direction during decryption
Encryption uses:
Decryption uses:
Reversing that order changes the result.
Letting spaces consume key positions without checking the convention
If the implementation skips spaces, then:
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:
Now decrypt:
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:
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:
and select the encryption operation. The tool applies the key across the message and returns the ciphertext.
For decryption, enter:
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:
you can decrypt directly.
If you have:
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
- Start with plaintext.
- Repeat the key across the message.
- Add each plaintext value to its key value modulo 26.
- Convert the results back to letters.
Formula:
Decryption
- Start with ciphertext.
- Repeat the same key across the message.
- Subtract each key value from its ciphertext value modulo 26.
- Convert the results back to letters.
Formula:
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.
Decrypting a message
You know the ciphertext and the key.
Breaking a message
You know the ciphertext but are trying to determine the key or 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.
