palAlaa
palAlaa

Reputation: 9858

Understanding the Hill cipher algorithm

I want to implement Hill cipher but I think I have a problem in understanding the algorithm itself.

The key I'll use is a 2X2 matrix and I'll encode 2 characters each time. I'll multiply the key matrix with the matrix of 2 characters then modulus the result on 26 as this equation.

C = E(K, P) = KP mod 26
where: K:key
       P:plain text

I do it like this but there's something wrong. I use the example in my book to test my algorithm. Since plain text is friday and key is: int key[][] = {{5, 8}, {17, 3}}; the result should be PQCFKU.

For the first letters f , r , f= 5 , r=17 order of alphabetic letters encryption of f is (5*5 + 17*8)%26 =5 => f it should be P

Where is the error that I make?

Upvotes: 1

Views: 1687

Answers (1)

robert_x44
robert_x44

Reputation: 9314

If this: http://slidefinder.net/c/chapter_classical_encryption_techniques_jen/11206531/p2 is your book, the matrix [[5, 8] [17, 3]] is not your encryption key... it is the input matrix. 5 = F, 17 = R, 8 = I, 3 = D. K is the encryption key, which is not given in the slide. You would have to solve the linear algebra equation to get K.

If you're still having problems with the example in your book, try http://www.cs.uri.edu/cryptography/classicalhill.htm for a simple 2x2 key example with both encryption and decryption.

Upvotes: 2

Related Questions