Strict Standards: Declaration of Doku_Renderer_metadata::table_open() should be compatible with Doku_Renderer::table_open($maxcols = NULL, $numrows = NULL, $pos = NULL) in /home2/cp-wiki/htdocs/inc/parser/metadata.php on line 480

Strict Standards: Declaration of Doku_Renderer_metadata::table_close() should be compatible with Doku_Renderer::table_close($pos = NULL) in /home2/cp-wiki/htdocs/inc/parser/metadata.php on line 480

Lab 14: First Hour

For today's lab, you are to work independently. You will have one hour to complete the assignment. If, at the expiration of this one hour, you are unfinished, submit what you have finished.

Write a program that will encrypt and decrypt simple lower-case strings using a substitution cipher, like a cryptoquote. The key, or the mapping from the plaintext letters to the code letters is given in cipher.txt. This is only one possible mapping, there are 26!-1 different mappings.

For example, one mapping is called rot13, where the alphabet is rotated halfway.


A B C D E F G ... 

maps to:

N O P Q R S T ...

You are given the following function that will read the mapping from a file. The function will return a list of pairs. It is your choice how to store the data for easy and efficient lookup. There is more than one good choice, so COMMENT in why you chose to do it this way. This comment is required.

def load_mapping(path):
    Load a mapping stored in a file at path.
    f = open(path)
    mapping = []
    for line in f:
        u,v = line.strip().split()
    return mapping
  • You will need to write two utility functions:
    • encrypt(encrypt_mapping, message): This function should take the mapping data and a message. It should perform lookups on the mapping, and replace all of the plaintext letters with the ciphertext letter indicated in the mapping, and return the enciphered string.
    • decrypt(decrypt_mapping, code):This function should take the mapping data and an enciphered message. It should perform lookups on the mapping, and replace all of the ciphertext letters with the plaintext letter indicated in the mapping, and return the deciphered string.
  • To check your code, either write a small main function or manually test in this order:
    1. Reads the given mapping in from the above file.
    2. Processes the mapping into the data structure of your choice.
    3. Prompts the user for a message to encipher.
    4. Encipher the message using the given mapping, and print out the enciphered message.
    5. Decipher the message using the mapping, and and print out the result.

Submit your program on Blackboard. Make sure you hand in everything you produce, as partial credit will be assigned accordingly.

cs190c/lab14.txt · Last modified: 2008/07/24 12:14 by seh
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki