Hacking Secret Ciphers with Python

(Ann) #1

12 http://inventwithpython.com/hacking


Email questions to the author: [email protected]


key is 26 or more, we should subtract 26 from it. So 27 – 26 is 1. The letter above the number 1 is
B. So the letter O encrypts to the letter B when we are using the key 13. One by one, we can then
encrypt the letters in, “Hello. How are you?” to “Uryyb. Ubj ner lbh?”


So the steps to encrypt a letter are:


1. Decide on a key from 1 to 25. Keep this key secret!


  1. Find the plaintext letter’s number.

  2. Add the key to the plaintext letter’s number.

  3. If this number is larger than 26, subtract 26.

  4. Find the letter for the number you’ve calculated. This is the ciphertext letter.

  5. Repeat steps 2 to 5 for every letter in the plaintext message.


Look at the following table to see how this is done with each letter in “Hello. How are you?” with
key 13. Each column shows the steps for turning the plaintext letter on the left to the ciphertext
letter on the right.


Table 1-1. The steps to encrypt “Hello. How are you?” with paper and pencil.
Plaintext
Letter

Plaintext
Number

+ Key Result Subtract
26?

Result Ciphertext
Letter
H 7 + 13 = 20 = 20 20 = U
E 4 + 13 = 17 = 17 17 = R
L 11 + 13 = 24 = 24 24 = Y
L 11 + 13 = 24 = 24 24 = Y
O 14 + 13 = 27 - 26 = 1 1 = B

H 7 + 13 = 20 = 20 20 = U
O 14 + 13 = 27 - 26 = 1 1 = B
W 22 + 13 = 35 - 26 = 9 9 = J

A 0 + 13 = 13 = 13 13 = N
R 17 + 13 = 30 - 26 = 4 4 = E
E 4 + 13 = 17 = 17 17 = R

Y 24 + 13 = 37 - 26 = 11 11 = L
O 14 + 13 = 27 - 26 = 1 1 = B
U 20 + 13 = 33 - 26 = 7 7 = H
Free download pdf