B.6 Examples for Chapter 6 – Introduction to Cryptography with Coding Theory, 3rd Edition

B.6 Examples for Chapter 6

Example 21

The ciphertext

22, 09, 00, 12, 03, 01, 10, 03, 04, 08, 01, 17

was encrypted using a Hill cipher with matrix

1234567810.

Decrypt it.

SOLUTION

There are several ways to input a matrix. One way is the following. A 2×2 matrix abcd can be entered as matrix(2,2,[a,b,c,d]). Type evalm(M&*N) to multiply matrices M and N. Type evalm(v&*M) to multiply a vector v on the right by a matrix M.

Here is the encryption matrix.

> M:=matrix(3,3,[1,2,3,4,5,6,7,8,10])
[ 1234567810 ]

We need to invert the matrix mod 26:

> invM:=map(x->x mod 26, inverse(M))
[ 8161821241241 ]

The command map(x->x mod 26, E) takes each number in an expression E and reduces it mod 26.

This is the inverse of the matrix mod 26. We can check this as follows:

> evalm(M&*invM)
[ 271305278313130130520209 ]
> map(x->x mod 26, %)
[ 100010001 ]

To decrypt, we break the ciphertext into blocks of three numbers and multiply each block on the right by the inverse matrix we just calculated:

> map(x->x mod 26, evalm([22,09,00]&*invM))

                           [14, 21, 4]

> map(x->x mod 26, evalm([12,03,01]&*invM))

                           [17, 19, 7]

> map(x->x mod 26, evalm([10,03,04]&*invM))

                            [4, 7, 8]

> map(x->x mod 26, evalm([08,01,17]&*invM))

                           [11, 11, 23]

Therefore, the plaintext is 14, 21, 4, 17, 19, 7, 4, 7, 8, 11, 11, 23. Changing this back to letters, we obtain overthehillx. Note that the final x was appended to the plaintext in order to complete a block of three letters.