A classical, poly-alphabetic cipher. Invented in 1533 by Giovan Battista Bellaso, misattributed to Blaise de Vigenère.
Each letter is shifted by an amount that depends on its position in the message, so the ciphertext letter frequencies are flattened. Also a stream cipher.
You can find an implementation of the Vigenère cipher in sahithyandev/ciphers.
Key Expansion
Repeat the key until it matches the plaintext length. Align each key letter with 1 plaintext letter.
Key Space
For a fixed keyword length , each position independently selects 1 of 26 shifts. The key space has members. Different allowed keyword lengths form separate key spaces, so the length must be specified when quoting the size.
Encryption
Assign each plaintext letter and its aligned key letter a value from to , where and . Add their values modulo . The result identifies the ciphertext letter.
Decryption
The key is repeated and aligned with the ciphertext the same way. Each ciphertext letter is shifted backward by the position of the key letter above it.
Tshifted back byL(11) givesIEshifted back byE(4) givesA
Attacking
Security depends significantly on keeping the key length secret. Once the key length is found, the cipher can be attacked in the same manner as a shift cipher, using statistical properties of the plaintext language for each block of ciphertext extracted from separate keyword positions.
Kasiski Test
Determines the keyword length.
Steps:
- Locate a repeating character sequence in the ciphertext.
- Count the distances between successive occurrences of that sequence.
- Take the greatest common divisor of these distances as the keyword length, or a multiple of it.
Repeated short strings, often common bigrams or trigrams of the language, that align to the same keyword position produce the same ciphertext string.
Fixed Transposition
A fixed transposition after Vigenère encryption does not remove the keyword’s period. Under Kerckhoffs’s principle, the transposition is public and an attacker reverses it before attacking the substitution.
If the transposition block length is a multiple of the keyword length , each block begins at the same keyword position.
The period therefore remains aligned across every block. Repeated ciphertext patterns still expose multiples of .
Worked Example
Plaintext finishhimfinishhim under keyword RUN, with to . The plaintext is the same short phrase said twice, so its repetition shows up directly in the ciphertext.
Solution Reveal Hide
The keyword is repeated to match the plaintext length.
| Plaintext | f | i | n | i | s | h | h | i | m | f | i | n | i | s | h | h | i | m |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Keystream | R | U | N | R | U | N | R | U | N | R | U | N | R | U | N | R | U | N |
| Ciphertext | W | C | A | Z | M | U | Y | C | Z | W | C | A | Z | M | U | Y | C | Z |
Each position adds the keystream letter modulo .
Ciphertext is WCAZMUYCZWCAZMUYCZ.
Decryption subtracts the keystream letter modulo at each position.
Numbering ciphertext positions from 1, the trigram WCA appears at positions 1 to 3 and 10 to 12.
Distance between the occurrences is . Only 1 distance is available, so the keyword length is a divisor of . Divisors are , , . Length is ruled out by trying it and getting non-language output. Length already recovers language, so the keyword length is .
Split the ciphertext into 3 columns, column holding positions . Each column is a shift cipher under one keyword letter.
Frequency analysis on each column recovers the shifts , which is the keyword RUN.
Decrypting with RUN gives finishhimfinishhim.