开发者

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 re开发者_JAVA技巧sult 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜