You are on page 1of 3

HILL CIPHER

1. Background: Matrices

a a
A 11 12
a 21 a 22

A is 2X2 matrix

2. Matrix multiplication:
a a b b
A 11 12 B 11 12
a 21 a 22 b21 b22

a b a b a11 b12 a12 b22


AB 11 11 12 21
a 21b11 a 22 b21 a 21b12 a 22 a 22

3. Matrix by vector multiplication


a a p
A 11 12 P 1
a 21 a 22 p2

a p a p
AP 11 1 12 2
a 21 p1 a 22 p2

4. Determinant of the 2X2 Matrix


a a12
A 11
a 21 a 22
det( A) a11 a 22 a 21 a12

5. Theorem: 2X2 matrix A is invertible modulo m if and only if det(A) is relatively


prime to m. In this case the inverse matrix is given by:
a a12
A 11
a 21 a 22

a 22 a12
A 1 (det( A)) 1 (mod m )
a 21 a11

1 0
AA 1 I (mod m )
0 1
Hill Cipher
Key Matrix: 2X2 matrix
Condition: The key matrix has to be invertible mod 26

Given Plaintext: p1p2p3p4..pn-1pn

a11 a12
Given Key Matrix: A
a 21 a 22

Encryption:
1. Form vectors as follows:
p1 p3 p5 pn 1
....
p 2 p4 p6 p n

2. Multiply each vector by A to obtain a pair of ciphertext letters:


p1 a11 a12 p1 c1
A (mod 26)
p2 a 21 a 22 p2 c 2

p a a12 p3 c 3
A 3 11 (mod 26)
p4 a 21 a 22 p4 c 4

...................
pn 1 a11 a12 pn 1 c n 1
A (mod 26)
pn a 21 a 22 p n c n

3. The ciphertext is: c1c2.cn

Decryption:

1. Calculate A-1
2. For each pair of ciphertext find a plaintext by:
c1 p1
A 1 (mod 26)
c 2 p2

c p
A 1 3 3 (mod 26)
c 4 p4

.......... .........
c n 1 pn 1
A 1 (mod 26)
c n pn

You might also like