Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Read carefully please, there is also 1 seperate function module and 1 main module. Thank you! Write and test the following function: def substitute(string, ciphertext):

Read carefully please, there is also 1 seperate function module and 1 main module. Thank you!

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

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions