Section 6.3 Hill's Cipher
Objectives
- Matrices
- Hill's Cipher
Subsection 6.3.1 Matrices
Definition 6.3.1. Matrix.
A matrix is a rectangular array of numbers such as
which, in this setting, we will use to represent a transformation for enciphering and deciphering.
The cipher we will look at in this section, Hill's Cipher will work much like an affine cipher but will use matrices for the multiplier and shift and not just numbers. All the matrices we will use will be either square like this
so that it has the same number of rows and columns or will be a special type of matrix called a vector which has only one column like this
Finally, all operations will be done using arithmetic modulo 26.
We can add and multiply matrices with one another or with vectors as long as the dimensions match.
Two \(2\times 2\) square matrices can be added like so
where the corresponding entries are added together. Then completing the addition and reducing modulo 26 we get
Likewise we can add two vectors
But, we cannot add a matrix to a vector since they are not the same size.
In order to multiply a matrix with a vector or a matrix with another matrix we need to multiply rows by columns like so
Breaking that down a little more, the first entry on top is
and the second entry on bottom is
When we simplify the result modulo 26 we get
Similarly we can multiply two matrices together
Before moving on to see how Hill used these ideas to create a cipher, practice your arithmetic with matrices and vectors, you will want to use Figure C.0.14 so that the multiplication is not so tedious.
Checkpoint 6.3.2.
Carry out the arithmetic operations and simplify the results modulo 26.
Checkpoint 6.3.3.
Carry out the arithmetic operations and simplify the results modulo 26.
Checkpoint 6.3.4.
Carry out the arithmetic operations and simplify the results modulo 26.
Checkpoint 6.3.5.
Carry out the arithmetic operations and simplify the results modulo 26.
Checkpoint 6.3.6.
Carry out the arithmetic operations and simplify the results modulo 26.
Subsection 6.3.2 Hill's Cipher
Subsubsection 6.3.2.1 Enciphering with Matrices
Let's see how we can encipher hill cipher
using a key matrix
Since it is a \(2\times 2\) matrix we will first break the message into groups of two letters
(hi) (ll) (ci) (ph) (er)
then to encipher each block we will convert each of these to a vector using \(a=0,\, b=1,\, c=2,\, \ldots\, etc. \) and multiply it by the matrix \(m\text{.}\) That is (hi)
becomes
Similarly we can encipher the (ll)
:
And for (ci)
we get:
Checkpoint 6.3.7.
Finish enciphering hill cipher
by enciphering the (ph)
and the (er)
just as we enciphered the other bi-grams.
Checkpoint 6.3.8.
Try to encipher the message linear madness
using the matrix
note that since the message has odd length you will need to tack on an extra null letter, like a z.
Checkpoint 6.3.9.
For a variation to Hill's Cipher you can both multiply by a matrix and add a shift, this make Hill's behave very much like an affine cipher. Try to encipher the word shifty
by first multiplying by the matrix
and then adding the vector
CKEADO
Subsubsection 6.3.2.2 Matrix Inverses and Deciphering
We will be able to decipher messages which used Hill's cipher in exactly the same way we enciphered them once we can find inverse matrices.
Definition 6.3.10. Inverse Matrix.
Given a matrix \(m\) the inverse matrix \(m^{-1}\) is the unique matrix such that
where \(I\) is the identity matrix (i.e. \(I\cdot m= m\cdot I = m\) for all matrices \(m\)).
Consider the matrix
the inverse for this will be
and if we multiply them together we get
which is the identity matrix since
for any values of \(a,\, b,\, c,\) and \(d\text{.}\) The matrix inverses and the identity matrix work just like the multiplicative inverses and multiplicative identities we discussed when we learned about affine ciphers and modular arithmetic; just as in that case, not all matrices will have a multiplicative inverse.
Definition 6.3.11. Determinant.
The determinant of a \(2\times 2\) matrix
is equal to
The matrix \(m\) will have a multiplicative inverse \(m^{-1}\) if and only if \(det(m)\) has a multiplicative inverse, in which case we get
Going back to our previous example of
we calculate the inverse as follows
which is what we had before.
Checkpoint 6.3.12.
Check your understanding by finding the inverse of
Checkpoint 6.3.13.
Check your understanding by finding the inverse of
Checkpoint 6.3.14.
Check your understanding by finding the inverse of
We are now, finally, ready to decipher a message. Suppose the message NDGUF SJV
had been enciphered using Hill's cipher with multiplier
to decipher we split the message into pairs and multiply those pairs by
So for the first two letters we get
And, for the next two letters of cipher text
Checkpoint 6.3.15.
Finish deciphering the message NDGUF SJV
.
Checkpoint 6.3.16.
Decipher the message TYEMC QDE
which was enciphered with the matrix
Checkpoint 6.3.17.
Decipher the message URYMB FXFLS
which was enciphered by multiplying the plain text by
and then adding the vector
- Find the inverse matrix \(m^{-1}\text{.}\)
- Change each pair of consecutive letters into a pair of numbers, this is a vector.
- Subtract the vector \(s\) from this vector.
- Multiply the new vector by the matrix \(m^{-1}\text{.}\)
- Reduce the result modulo 26 and change back to letters, this is your plain text.
hello again
In conclusion we can give Hill's cipher the following general definition.
Definition 6.3.18. Hill's Cipher.
Hill's cipher is a cipher with a two part key, a multiplier \(m\) which is a square \(n\times n\) matrix and a shift \(s\) which is a vector with \(n\) entries; typically all the arithmetic is done modulo 26. Characters of the plain text are enciphered \(n\) at a time with the formula
where \(plain\) is a vector of \(n\) characters. Likewise, characters of the cipher text are deciphered \(n\) at a time with the formula
or
Note that the multiplier \(m\) must have a multiplicative inverse.
We end with two important observations. First, modern explanations of Hill's cipher focus on the simplest case when the matrix has dimension \(2\times 2\) and there is no shift. Second, you should be able to see that Hill's cipher is a variation on a affine cipher which enciphers multiple characters at a time in order to mix up the frequencies, this means it is a type of polygraphic cipher.