2nd Lecture
2nd Lecture
2
C.N. Security lec 4 ENG. AHMED K. DARAJ
Hill cipher
The Hill cipher uses matrix multiplication, mod 26. In particular, the
encryption key is an nxn matrix with an inverse mod 26, where n is the block size.
System can be described as follows:
C = KP mod 26
For example, we will illustrate the cipher with n=2. Consider the following
key:
3 1
6 5
12
0 stands for "ma"
Now, multiply the encryption key by the plaintext and reduce mod 26 to get the
ciphertext:
3 1 12 36 10
mod 26 = mod 26 = , which corresponds to the ciphertext KU.
6 5 0 72 20
3 1 19 64 12
mod 26 = mod 26 = , which corresponds to the ciphertext MT.
6 5 7 149 19
Ciphertext: KUMT
Example: consider the plaintext "paymoremoney" and use the encryption key:
The first three letters of the plaintext are represented by the vector
The ciphertext for the entire plaintext is: LNS HDL EWM TRW.
Decryption:
P = K-1 C mod 26
To find K-1 it needs to use a bit of math. It turns out that K-1 above can be
calculated from our key. The important things to know are inverses (mod m),
determinants of matrices and matrix adjugates.
C.N. Security lec 4 ENG. AHMED K. DARAJ
Determinant 1 3 5 7 9 11 15 17 19 21 23 25
Reciprocal Modulo 26 1 9 21 15 3 19 7 23 11 5 17 25
Example: decrypt the following ciphertext " KUMT" if you know it is encrypted
using Hill cipher by key
3 1
6 5
Solution:
d= 3*5 –(1*6) = 9
d-1 = 3
5 − 1
adj(k) =
− 6 3
15 23
k-1 =d-1 * adj(k) =
8 9
Now, we can corroborate that this is the case by decrypting the example above.
Plaintext: math
Example of decryption 3x3 key: decrypt the following ciphertext "LNS HDL
EWM TRW " if you know it is encrypted using Hill cipher key
C.N. Security lec 4 ENG. AHMED K. DARAJ
Solution:
p=k-1*C mod 26
(23)-1=17 17 21 2
17 18 2
The adjugate of the 3×3 matrix and then transpose is 5 21 19
300 −313 267 𝟒 𝟗 𝟏𝟓
([−357 313 −252] ∗ 17 ) mod 26 =[𝟏𝟓 𝟏𝟕 𝟔 ] this is K-1
6 0 −51 𝟐𝟒 𝟎 𝟏𝟕
𝑝1 4 9 15 11
[𝑝2] = [15 17 6 ] *[13] 𝑚𝑜𝑑 26
𝑝3 24 0 17 18
And repeat the same function to the next three letters until end the ciphertext
Example: Suppose that the plaintext "friday" is encrypted using a 2 x 2 Hill cipher
to
Solution:
C.N. Security lec 4 ENG. AHMED K. DARAJ
So: