Vigenère cipher is one of the classic encryption algorithms. It belongs to the group of the so-called polyalphabetic substitution ciphers. This cipher was mistakenly assigned to the creator of the more complicated cipher Blaise de Vigenère.
The cipher we now call the Vigenère cipher was first described by Giovan Batista Belaso in 1553, in a brochure entitled La cifra del. Sig. Giovan Batista Belaso.
The operation of the Vigenère cipher is based on a code table:
| ABCD EFGH IJKL MNOP QRST UVWX YZ
A | ABCD EFGH IJKL MNOP QRST UVWX YZ
B | BCDE FGHI JKLM NOPQ RSTU VWXY ZA
C | CDEF GHIJ KLMN OPQR STUV WXYZ AB
D | DEFG HIJK LMNO PQRS TUVW XYZA BC
E | EFGH IJKL MNOP QRST UVWX YZAB CD
F | FGHI JKLM NOPQ RSTU VWXY ZABC DE
G | GHIJ KLMN OPQR STUV WXYZ ABCD EF
H | HIJK LMNO PQRS TUVW XYZA BCDE FG
I | IJKL MNOP QRST UVWX YZAB CDEF GH
J | JKLM NOPQ RSTU VWXY ZABC DEFG HI
K | KLMN OPQR STUV WXYZ ABCD EFGH IJ
L | LMNO PQRS TUVW XYZA BCDE FGHI JK
M | MNOP QRST UVWX YZAB CDEF GHIJ KL
N | NOPQ RSTU VWXY ZABC DEFG HIJK LM
O | OPQR STUV WXYZ ABCD EFGH IJKL MN
P | PQRS TUVW XYZA BCDE FGHI JKLM NO
Q | QRST UVWX YZAB CDEF GHIJ KLMN OP
R | RSTU VWXY ZABC DEFG HIJK LMNO PQ
S | STUV WXYZ ABCD EFGH IJKL MNOP QR
T | TUVW XYZA BCDE FGHI JKLM NOPQ RS
U | UVWX YZAB CDEF GHIJ KLMN OPQR ST
V | VWXY ZABC DEFG HIJK LMNO PQRS TU
W | WXYZ ABCD EFGH IJKL MNOP QRST UV
X | XYZA BCDE FGHI JKLM NOPQ RSTU VW
Y | YZAB CDEF GHIJ KLMN OPQR STUV WX
Z | ZABC DEFG HIJK LMNO PQRS TUVW XY
As can be seen, each row of the table corresponds to the Caesar Cipher, the shift is 0 in the first line, 1 in the second, 2 in the third, etc.
A password is needed to encrypt some text. The password tells which row (or column) should be used at the moment.
Suppose we want to encrypt a simple text, e.g:
THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
For this purpose, we will use a password known only to us, for example: SECRET
At the beginning, we note that the password used is too short to encrypt the entire text, so be sure to use multiple of it. It will look like this:
Message: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
Password: SEC RETSE CRETS ECR ETSEC RETS ECR ETSE CRE
The encryption is performed as follows: the letter of the ciphertext corresponds to the letter from the table located at the intersection of the line, determined by the letter of the plaintext, and the column determined by the password letter, e.g. sequentially „T” & „S” make „L”, „H” & „E” make „L” etc. As a result, we get the encrypted text:
LLG HYBUO DISPF JQO NNETU FZXJ XJV PTRC FFK
It's worth noting that it doesn't really matter whether the plaintext letter designates the row and the keyword the column, or vice versa, the effect of the encryption will always be the same.
Decryption is very similar. We take the letters of the ciphertext and the corresponding letters of the keyword (similar to encryption). We choose the column corresponding to the letter of the keyword. Then in this column we look for the letter of the ciphertext. The line number corresponding to the letter found is the letter number of the plaintext. For example, in the 'T' column the letter "L" is in the 'T' line, in the 'E' column the letter "L" is in the 'H' line, etc.
There is, however, a simpler, particularly for implementation purposes, method of decryption. It requires a simple password 'invert' operation as follows:
- K2(i) = [26 – K(i)] mod 26
where K(i) – next letter of the password, numbered A=0, B=1 etc., and K2(i) – the next letter of the "inverted" password. 26 is the number of letters of the Latin alphabet.
Then, the encryption operation should be performed on the ciphertext with the received password. The result, as you can see, will be the public form of the text.
When using the alphabetic key version, the first row of the code table will be a keyed alphabet. The key is appended to the alphabet without repeating characters.
Let our alphabet key be the word KEY . We add them e.g. at the beginning of the alphabet. Our keyed alphabet will now be:
KEYABCDFGHIJLMNOPQRSTUVWXZ
The rest of the encryption / decryption activities are performed in the same way as in the version without the alphabet key, using the code table with the key.
It is obvious that adding an alphabet key increases the security of the ciphertext. Because to decode, apart from the password, you also need an alphabet key.
More on: Wikipedia - Vigenère cipher