Question
Write and test the following function: def substitute(string, ciphertext): ------------------------------------------------------- Encipher a string using the letter positions in ciphertext. Use: estring = substitute(string, ciphertext):
Write and test the following function:
def substitute(string, ciphertext): """ ------------------------------------------------------- Encipher a string using the letter positions in ciphertext. Use: estring = substitute(string, ciphertext): ------------------------------------------------------- Preconditions: string - string to encipher (str) ciphertext - ciphertext alphabet (str) Postconditions: returns estring - the enciphered string (str) ------------------------------------------------------- """
Add this function to the PyDev module asgn01.py. Test it from q1.py.
This function uses a substitution cipher in which a letter is replaced with another based upon a substitution or ciphertext alphabet. To encipher text, look up the position of a letter in the standard alphabet and replace it with the letter in the same position in the ciphertext alphabet.
Plaintext alphabet: | ABCDEFGHIJKLMNOPQRSTUVWXYZ |
Ciphertext alphabet: | DAVIBROWNZCEFGHJKLMPQSTUXY |
In this example A is replaced by D, B is replaced by A, C is replaced by V, and so on. Leave all other characters unchanged. Convert the input to uppercase for the enciphering and make the output entirely uppercase. The function should work with an empty string.
Test this function using the file pelee.txt. Write the encrypted text to a file named substitute.txt.
pelee.txt:It appears that Ontario's Point Pelee National Park has lost its point. The southernmost tip of Canada is in the park, near the town of Leamington. There have always been several hundred metres of sand jutting out from the mainland. But park officials say recent high winds have washed away the sand point and all that remains is a platform. The park advertises itself as the southernmost tip of Canada's mainland, at the same latitude as northern California, and attracts more than 400,000 visitors per year. A park official says a no swimming sign that used to mark the southernmost point washed up on a beach in Madison, Ohio, about 100 kilometres across Lake Erie. Officials say the sand patterns at the point change frequently, but this is the first time the point has disappeared completely.
Step by Step Solution
3.51 Rating (168 Votes )
There are 3 Steps involved in it
Step: 1
def substitutestring ciphertext convert to uppercase res stringuppe...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Document Format ( 2 attachments)
635e0b921dc65_180979.pdf
180 KBs PDF File
635e0b921dc65_180979.docx
120 KBs Word File
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started