Txtcodec

Indices and tables

Background

Encrypting messages to prevent eavesdropping started thousands of years ago. One simple method of encryption os the substitution cipher, where one letter is replaced with another and the length of the string is maintained. An example of this is ROT13.

Exercise

Implement a program to encode and decode messages using a substitution cipher.

The program should allow the user to:

  1. Indicate which operation to perform (encrypt, decrypt)
  2. Read the message to encrypt / decrypt from the command line
  3. Print the output message to the terminal

Hints

The string class is your friend.

Review the sys package for details on using sys.argv as a simple way to get the command line arguments.

Solution

When you are ready to see one possible solution, try this file