Question: Write and test the following function: def shift(string, n): ------------------------------------------------------- Encipher a string using a shift cipher. Use: estring = shift(string, n): ------------------------------------------------------- Preconditions:
Write and test the following function:
def shift(string, n): """ ------------------------------------------------------- Encipher a string using a shift cipher. Use: estring = shift(string, n): ------------------------------------------------------- Preconditions: string - string to encipher (str) n - the number of letters to shift (int) Postconditions: returns estring - the enciphered string (str) ------------------------------------------------------- """
Read carefully please, there's 1 funciton module and 1 main. Thank you!
Add this function to the PyDev module asgn01.py. Test it from q2.py.
This function uses a shift cipher in which each letter is replaced by another letter that is n positions to the right of the first letter. (A shift of 26 would leave the original string unchanged.) You may not use a look-up table as in the previous question - you must determine the replacement letters mathematically. 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 shift.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
Get step-by-step solutions from verified subject matter experts
