Lab 9: Substitution Cipher
Web-CAT: Submit Python programs to this automated grading platform.
Task Outline
- Due Date: Friday, November 22, 2019
- Total Points: 10
- Implement a
Pythonprogram that encrypts a message using the substitution cipher.
Background Theory
- In a substitution cipher, we encrypt a message by replacing every letter in a plaintext message with some other letter.
- In order to perform this encryption, we make use of a key. In the case of the substitution cipher, the key is a mapping of each of the letters of the alphabet to the letter that it should correspond to, when we encrypt it.
- To decrypt the message, the receiver of the message would need to know the key, so that they could reverse the process.
- A key, for example, might be the string
jtrekyavogdxpsncuizlfbmwhq. This 26-character key means thata(the first letter of the alphabet) should be converted intoj(the first letter of the key). Similarly, the letterb(the second letter of the alphabet) should be converted intot(the second letter of the key) and so on. - Therefore, a message like
hellowould be encrypted asvkxxn, replacing each of the letters according to the mapping as determined by the key.
Code Distribution
| Description | File Size | File Name |
|---|---|---|
Python Source Code for Substitution Cipher |
1.7KB | lab09.zip |
Contents of lab09.zip:
Lab09SubstitutionCipher/
├── substitutioncipher.py
└── testsubstitutioncipher.py
Specification
- Write a
Pythonprogram in the filesubstitutioncipher.pythat encrypts a message using the substitution cipher. - You will write your solution in a function called
encrypt(message, key)right below the place where it says:YOUR CODE HERE - When the function call
encrypt("hello", "jtrekyavogdxpsncuizlfbmwhq")is executed, the output of the program should be:vkxxn
Testing
- Run the file
testsubstitutioncipher.pyto execute thePyUnittest bench.PyUnitindicates a successful test with anOKoutput, and an unsuccessful test with aFAILoutput.
Submission
- Upload the file
substitutioncipher.pyto the Web-CAT automated grading platform.