University of Dohuk
Faculty of science
Computer science department
Hill Cipher
Lecture 5
Hill Cipher
• Another interesting multi letter cipher is
the Hill cipher, developed by the
mathematician Lester Hill in 1929. The
encryption algorithm takes m successive
plaintext letters and substitutes for them
m ciphertext letters.
• c1 = (k11P1 + k12P2 + k13P3)P11 mod 26
• c2 = (k21P1 + k22P2 + k23P3) p12mod 26
• c3 = (k31P1 + k32P2 + k33P3) p13mod 26
Hill Cipher
• Block cipher
• Choose an integer N and generate a key
which is an N×N matrix whose entries are
integers modulo 26
• Write the message as series of row vectors of
size N
• To encrypt multiple each vector with the key
and reduce mod 26
• To decrypt find inverse of key (matrix) mod
26 and multiply the ciphertext from left with
it
c1
c2 This can be expressed in term of column vectors and matrices:
c3
OR
C = KP mod 26
where C and P are column vectors of length 3,
representing the plaintext and ciphertext, and K is
a 3 x 3 matrix, representing the encryption key.
Operations are performed mod 26.
Hill Cipher
• 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 Z26. 26 was chosen because
there are 26 characters, which solves some
problems later on.
Hill Cipher example
Encryption:
where the space = 0
A B C D E F G H I J K L M N O P Q R S
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
T U VW X Y Z
20 21 22 23 24 25 26
Consider the following message:
Note :- without space counting
Herbert Yardley wrote The American Black Chamber
Hill Cipher example
Break the message into:
he rb er ty ar dl ey wr ot et he am er ic an bl ac kc ha mb er
Now convert letters into number-pair:
8 5 18 2 5 18 20 25 1 18 4 12 5 25 23 18 15 20
5 20 8 5 1 13 5 18 9 3 1 14 2 12 1 3
11 3 8 1 13 2 5 18
Now using the matrix (key) 03 07
K
05 12
Hill Cipher example
Make the first pair a column vector (h (8) e (5)),
and multiply that matrix by the key.
3 7 8 59
5 12 5 100
Of course, we need our result to be mod 26
59 7
100 22 mod 26
The ciphertext is G (7) V (22).
Hill Cipher example
For the next pair r (18) b (2),
3 7 18 16
5 12 2 10 mod 26
and 16 corresponds to P and 10 corresponds to J.
Do this for every pair and obtain
GVPJKGAJYMRHHMMSCCYEGVPEKGVCWQLXXOBMEZAKK
G
Hill Cipher Decryption:
Decrypting:
- multiply each block by K-1
03 07
K
How to invert a matrix K ? 05 12
- invertible (mod 26) if gcd(det(K),26)=1
- if m=2 and invertible, then:
K-1= (3*12-5*7) -1 ×
First find det(k)-1=(3*12-5*7) mod 26=
36-35 mod 26 =1
Then gcd(det(k)-1, 26)=1 , it means there is inverse matrix
Second : 1 × mod 26
1*12 mod 26=12 : 1* -7 mod 26=19 : 1* -5 mod 26=21 : 1*3 mod 26=3
Hill Cipher Decryption:
03 07
K =
-1
K
05 12
Now we decrypt The ciphertext is GV
12 19 7 8
G (7) V (22). 21 3 22 5
(1,1)=(12 * 7 +19*22)mod 26 =502 mod 26=8
(2,1)=( 21*7 +3*22)mod 26=213 mod 26=5
Then 8=h , 5=e
EXAMPLE:
Note: Alphabet order start from zero
Consider the message 'ACT', and the key below
(or GYBNQKURP in letters):
Since 'A' is 0, 'C' is 2 and 'T' is 19, the
message is the vector:
Thus the enciphered vector is given by:
which corresponds to a ciphertext of 'POH'
We find that in the inverse matrix of the one in the
previous example is:
Taking the previous example ciphertext of
'POH', we get:
which gets us back to 'ACT'.
Basis of modern ciphers
• Claude Shannon - information theory
• product cipher
– perform two or more ciphers in sequence so that
result (product) is cryptographically stronger than
any component cipher
• alternate confusion & diffusion
• virtually all significant symmetric block ciphers
currently in use are of this type
Shannon’s strategy
• cryptanalysis that is based on statistical analysis
• hacker has some knowledge of statistical
characteristic of plaintext
• if statistics are reflected in ciphertext, then analyst
may be able to deduce encryption key, or part of it
• in Shannon’s ideal cipher, statistics of ciphertext
are independent of plaintext
Shannon’s building blocks
• confusion
– make relation between statistics of ciphertext and
the value of the encryption key as complex as
possible
• diffusion
– diffuse statistical property of plaintext digit across a
range of ciphertext digits
– i.e. each plaintext digits affects value of many
ciphertext digits
Shannon’s building blocks
• Shannon proposed product ciphers with
two components
– S-Boxes -- substitution
• providing confusion of input bits
– P-Boxes -- permutation
• providing diffusion across S-box inputs
• n rounds of S-P boxes
Shannon’s building blocks
• Shannon proposed product ciphers with
two components
– S-Boxes -- substitution
• providing confusion of input bits
– P-Boxes -- permutation
• providing diffusion across S-box inputs
• n rounds of S-P boxes
• H.W
• 1:- How to invert a matrix K (3*3)
• 2:- Different between
Q1
Alice want to send message to Bob
Plain text= ” Password is “
The key is= “ Institution “
she used Play Fair methods .
Q2
Alice want to send A message to Bob the message
is “ meet me “ she used Affine cipher
By using K1=11, K2=5
Encrypt and Decrypt the message