07.07.2023 Views

Implementing-cryptography-using-python

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 4 ■ Cryptographic Math and Frequency Analysis 119

Because we started with a 3 × 3 encoding matrix, we will break the enumerated

message into a sequence of 3 x 1 vectors:

16

18

05

16

01

18

05

27

20

15

27

14

05

07

15

20

09

01

20

05

27

There are only 20 characters in the message; since we have a matrix with 21

positions, we need to populate the last position with a space (27) to complete

the last vector. We may now encode the message by multiplying each of the

preceding vectors by the original encoding matrix:

– 3– 3–

4

0 1 1

4 3 4

16 16 05 15 05 20 20

18 01 27 27 07 09 05

05 18 20 14 15 01 27

This will produce the following encoded message that can be transmitted

in a linear form:

−122, 23, 138, −123, 19, 139, −176, 47, 181, −182, 41, 197, −96, 22, 101, −91, 10, 111,

−183, 32, 203

To decrypt the message, the recipient writes the message as a sequence of a

3 × 3 matrices and uses the inverse of the encoding matrix:

1 0 1

4 4 3

– 4– 3–

3

With the inverse, you can perform matrix multiplication on the received

message:

1 0 1

4 4 3

– 4– 3–

3

– 122 – 123 – 176 – 182 – 96 – 91 183

23 19 47 41 22 10 32

138 139 181 197 101 111 203

The matrix multiplication should produce the following:

16 16 05 15 05 20 20

18 01 27 27 07 09 05

05 18 20 14 15 01 27

Once you have the matrix calculated, you should be able to expand the message

and map the numbers back to their original letters:

P R E P A R E T O N E G O T I A T E

16 18 05 16 01 18 05 27 20 15 27 14 05 07 15 20 09 01 20 05

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!