Mathematics of the Vigenere Cipher
by fortenforge, Aug 21, 2009, 9:21 PM
Ok, so I lied. I said that the next post was going to be about why frequency analysis fails on the Vigenere cipher but I decided to talk about how to mathematically define the cipher.
Let us say that we have already translated our plaintext into numbers (A = 0, B = 1, C = 2, ...). Let us say that the numbers are
.
Let us say that we have chosen a key of length
and the letters of our key transformed into numbers are
.
To encrypt plaintext number
we use
where
. This accounts for the fact that the key is repeated over each letter of the plaintext. We use mod
because
is the length of the keyword.
Call
the corresponding ciphertext number to
.
where
.
The first part is just the Caesar Cipher mathematically. The only difference is that as
changes
changes as well. This is what makes the Vigenere cipher a much better code.
Let's take an example:
plaintext: BLITZKRIEG
Numerical equivalent: 1 11 8 19 25 10 17 8 4 6
keyword: WAR
Numerical equivalent: 22 0 17
For the
th number of our plaintext,
, to find the equivalent key letter we take
. So we take the
th keyword number which is
.
For the
th number of our plaintext,
to find the equivalent key letter we take
. So we take the
nd keyword number which is
.
We would continue this process for all the letters there by finding each letters keyword equivalent.
Notice that the first number in our list is being considered as our 0th number and the 2nd number is being considered as the 1st number to make the math work. In cryptography this is normal.
You can see that this method works by verifying it here:
WARWARWARW
BLITZKRIEG
The math method and the visual method match up, the 0th plaintext letter corresponds to the 0th key letter and the 5th plaintext letter corresponds to the 2nd key letter.
If we wanted to encrypt the 0th letter mathematically we would find:
. So our 0th ciphertext number is 23.
If we wanted to encrypt the 5th letter mathematically we would find:
. So our 5th ciphertext number is 1.
We would continue the process for all the letters.
Again when doing it mathematically and doing it without math you get the same ciphertext:
XLZPZBNIVC.
Learning what a cipher is mathematically is not much useful if you are decrypting a message by hand, but it is enormously useful if you are trying to program a cipher on a computer.
Let us say that we have already translated our plaintext into numbers (A = 0, B = 1, C = 2, ...). Let us say that the numbers are

Let us say that we have chosen a key of length


To encrypt plaintext number





Call




The first part is just the Caesar Cipher mathematically. The only difference is that as


Let's take an example:
plaintext: BLITZKRIEG
Numerical equivalent: 1 11 8 19 25 10 17 8 4 6
keyword: WAR
Numerical equivalent: 22 0 17
For the





For the





We would continue this process for all the letters there by finding each letters keyword equivalent.
Notice that the first number in our list is being considered as our 0th number and the 2nd number is being considered as the 1st number to make the math work. In cryptography this is normal.
You can see that this method works by verifying it here:
WARWARWARW
BLITZKRIEG
The math method and the visual method match up, the 0th plaintext letter corresponds to the 0th key letter and the 5th plaintext letter corresponds to the 2nd key letter.
If we wanted to encrypt the 0th letter mathematically we would find:

If we wanted to encrypt the 5th letter mathematically we would find:

We would continue the process for all the letters.
Again when doing it mathematically and doing it without math you get the same ciphertext:
XLZPZBNIVC.
Learning what a cipher is mathematically is not much useful if you are decrypting a message by hand, but it is enormously useful if you are trying to program a cipher on a computer.