Python Chapters
Making a program to decipher by substitution.
Deciphering is the reverse of enciphering, so we can use the same programming techniques that we've already learned. The design of the program is called an algorithm, and it's useful to write this out before starting to program.
You begin the program with declarations of the cipher and also ‘plain’, ‘key’ and ‘alphabet’ like this:
cipher=’’’ACRMQ IFNFU DQFQZ OMOHM HIHAD TFKQZ OPHEE FTQZO KRDDA DIQAN OAMHU AENPH EEHDN HPEOH KPHEE QZHQC HWDFQ YONOD AON’’’
key = 'HYPNOTIZABLECDFGJKMQRSUVWX'
alphabet = 'abcdefghijklmnopqrstuvwxyz'
plain = ‘’
Now the algorithm:
remove spaces from ciphertext
take each character in ciphertext:
if it is not a space:
find its position in the key
find letter in same position in alphabet
add alphabet letter to the string ‘plain’
print out ‘plain’ in Python Shell
The full program is shown in Appendix 3. When you run the program of course you get back the plaintext, but without spaces at the end of each word:
imustgodowntotheseasagainforthecalloftherunningtideisawildcallandaclearcallthatmaynotbedenied