Hill Cipher Decryption, 2by2 Matrix
Order 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Alphabetic A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Example: Decrypt the C = “HIAT” using Hill cipher given the key = 3 3
2 5
1. We need to convert the Cipher text into matrix form, since the key is already in the matrix form then the Cipher text become like this
H A
I T
Order 7 8 0 19
Alphabetic H I A T
7 0
Substitute the value order for each Ciphertext letters
8 19
2. Dived the Ciphertext into 2 letters on other meaning into 2-separate columns. 7 0
8 19
3. Cipher text C= K*P mod 26. Remember that the multiplication is not the normal multiplication it’s a matrix’s multiplication. So, the
formula for P = (Key inverse) K-1 * C mod 26.
4. Now we should find the K-1 , the Key inverse following this simple rule:
𝟏
(1/determinant K multiply by adjoint K) in math expression we write it like this ⋮𝑲⋮ *Adj K
4.1 Now we should find determinant K, according to the following rule
To find any determinant for 2x2 matrices,
𝑨 𝑪
K= determinant K = (A*D) – (C*B)
𝑩 𝑫
𝟑 𝟑
In our example K= determinant K = (3*5) – (3*2) = 15 – 6 = 9
𝟐 𝟓
4.2 Now we should find adjoint K, according to the following rule
To find any adjoint for 2x2 matrices,
𝑨 𝑪 𝑫 −𝑪
K= adjoint K=
𝑩 𝑫 −𝑩 𝑨
𝟑 𝟑 𝟓 −𝟑
In our example K= adjoint K =
𝟐 𝟓 −𝟐 𝟑
5. Now substitute what we get from steps 4.1 and 4.2 above in the rule on step number 3 above we get:
𝟏 𝟏 𝟓 −𝟑
*Adj K *
⋮𝑲⋮ ⋮𝟗⋮ −𝟐 𝟑
𝟏
5.1 we need to find the inverse for , by following the Extended Euclidean Algorithm and Inverse Modulo, but in general what
⋮𝟗⋮
𝟏
meant by inverse its means that 9 * X mod
⋮𝟗⋮
, 26= 1, now what is the value for X?
Start from number 1 and substitute it in X we get:
9 * 1 mod 26= 9 not = 1
9 * 2 mod 26= 18 not = 1
𝟏
9 * 3 mod 26= 27 = 1, then inverse ⋮𝟗⋮
=3
5.2 we continue the solution by substitute the result we got from step 5.1 above
𝟓 −𝟑
3 * mod 26, Since in mod we don’t have a negative sign for that we add 26 to all negative sign,
−𝟐 𝟑
then we get:
𝟓 𝟐𝟑
3 * mod 26
𝟐𝟒 𝟑
5.3 we continue the solution by using the result we got from step 5.2 above
𝟓 𝟐𝟑 𝟏𝟓 𝟔𝟗 𝟏𝟓 𝟏𝟕 𝟏𝟓 𝟏𝟕
3 * mod 26 = mod 26 = K-1 =
𝟐𝟒 𝟑 𝟕𝟐 𝟗 𝟐𝟎 𝟗 𝟐𝟎 𝟗
6. Substitute what we get above in Decryption rule (P= (Key inverse) K-1 *C mod 26) we get:
𝟏𝟓 𝟏𝟕 𝑯 = 𝟕 (𝟏𝟓 ∗ 𝟕) + (𝟏𝟕 ∗ 𝟖) = 𝟐𝟒𝟏 𝟕=𝑯
P= * mod 26 MOD 26 =
𝟐𝟎 𝟗 𝑰 = 𝟖 (𝟐𝟎 ∗ 𝟕) + (𝟗 ∗ 𝟖) = 𝟐𝟏𝟐 𝟒=𝑬
7. Again, we repeat the step 6 above for the next column:
𝟏𝟓 𝟏𝟕 𝑨 = 𝟎 (𝟏𝟓 ∗ 𝟎) + (𝟏𝟕 ∗ 𝟏𝟗) = 𝟑𝟐𝟑 𝟏𝟏 = 𝑳
P= * mod 26 MOD 26 =
𝟐𝟎 𝟗 𝑻 = 𝟏𝟗 (𝟐𝟎 ∗ 𝟎) + (𝟗 ∗ 𝟏𝟗) = 𝟏𝟕𝟏 𝟏𝟓 = 𝑷
8. Finally, the Ciphertext “HIAT” Is Decrypted to “HELP”.