Cryptography ( 31 Jan 2020 )

Cryptography is an ancient study of secret writing. There is a wealth of literature in this field. An extremely readable book on this subject is The Code Book by Simon Singh. This is a field of study that is of particular relevance in Computer Science. Given the widespread use of computers, one of the things people are interested in is making transactions over the internet more secure.

For the purposes of this exercise convert the message that you are asked to encode or decode to lower case. You will only be encoding or decoding the letters of the alphabet. Punctuation marks and numerals remain untouched.

Substitution Cipher: In this method you will replace the letters using the following scheme.

Plain Text:  a b c d e f g h i j k l m n o p q r s t u v w x y z
Cipher Text: q a z w s x e d c r f v t g b y h n u j m i k o l p
Save the Cipher letters in a list of characters.
cipher = [ 'q', 'a', 'z', ...., 'o', 'l', 'p' ]
To find the substitution for the character d first convert d into an index for the array cipher as follows:
idx = ord ('d') - ord ('a')
Then use that index (whose value in this case is 3) to access the character that will be a substitute for d (in this case cipher[3], which is w. The Caesar Cipher is also a substitution cipher that can be easily decoded.

Substitution Cipher

Enter Plain Text to be Encoded: hello world
Encoded Text: dsvvb kbnvw

Enter Encoded Text to be Decoded: dsvvb kbnvw
Decoded Plain Text: hello world

References