Hill Cypher
The Hill Cipher uses matrix multiplication to encrypt a message. First, you need to assign two numbers to each letter in the alphabet and also assign numbers to space, . , and ? or !. The key space is the set of all invertible matrices over Z29. 29 was chosen because there are 29 characters and it is also a prime number, which solves some problems later on. The encryption function, in its most basic form looks like this:
ek(x)=k (x)
Here is an example:
F o u r s c o r e a n d ….
06-15-21-18-00-19-03-15-18-05-00-01-14-04….
The key, k, will be a 2x2 matrix. For example
{ 03 05}
K= { 02 07}
To encrypt the message, we take two letters at a time and make a vector. Thus "Fo" becomes the vector
{ 06 }
V= { 15 }
You then encrypt V by multiplying by K and reducing mod 29:
V---->KV mod 29
{ 06 } x { 03 05 } = { 93 } = { 6 }
{ 15 } x { 02 07 } = { 117 } = { 1 }
Therefore, UR encrypts into 18, 06, and space S encrypts into 14, 25.
In order to decrypt, you first need to find the inverse of your original 2x2 matrix. First, you need to figure out the determinate:
{ a b }
{ c d } AD-BC=determinate
Then, you negate C and B, switch A and D, and multiply everything by the determinate. Then reduce by mod 29.
21 - 10 = 11
Then find the multiplicative inverse of the determinate and multiply each number in the original number in the key by it:
7 * 8 = 56 mod 29 = 27 // 3 * 8 = 24 mod 29 = 24 // 2 * 8 = 16 mod 29 = 16 // 5 * 8 = 40 mod 29 = 11
Inverse of Key: { 56 192 }
{ 216 24 }
Then multiply the encrypted matrix by the inverse of the key:
{ 6 } * { 56 192 } = { 6 }
{ 1 } * { 216 24 } = { 15 }