Answered step by step
Verified Expert Solution
Question
1 Approved Answer
secretMessage2.txt secretMessage1.txt Problem: In this lab, you will create a new Python program (lab2.py). In that program, you will ask the user for the name
secretMessage2.txt
secretMessage1.txt
Problem: In this lab, you will create a new Python program (lab2.py). In that program, you will ask the user for the name of a text file. You should check that this file ends with a ".txt" extension. If it does not, print an error message on the screen and continue to ask the user for the name of a text file until a valid one is provided. This is the only validation you need to do for the file name you can assume that the .txt file exists in the same directory as your Python file. This should all be done in a function called getInputFile(), which returns the valid name of the text file as a string. When provided with a valid text file name, you can assume that the file will contain exactly two lines. The first line will consist of a positive integer: this is the cipher key. The second line will consist of a series of encrypted words, where each word is encoded using the Caesar cipher described above. You are tasked with decrypting the message, and printing the clear message (all in lower case letters) to the screen. For example, if you have a cipher key of 1, the encrypted message IfmmP XpsMe becomes hello world. This should all be done in a function called decrypt(filename). Things to keep in mind: 1. Both lines in the text file may or may not have leading and/or trailing whitespace that you should strip away before processing the data. 2. There are an unknown number of encrypted words in the text file, and these words are separated by inconsistent whitespace (e.g. tabs, single space, multiple spaces). Your decrypted message should separate each word by a single space. You can include a single space after the last word in your decrypted message. 3. You can assume that the encrypted words will only contain letters (i.e. no numbers, punctuation, or symbols), but these letters could be uppercase or lowercase. Your decrypted message should only contain lowercase letters. 4. The cipher key can be greater than 26 . 5. Letters should wrap around, so that if you have a cipher key of 1 , the encrypted message qjaab becomes pizza. Be sure to include a docstring at the top of each of your function definitions. In Python, docstrings are located on the line directly after def function_name (param1, ...) : and is indented one level. The docstring may be one line or many lines, but must be enclosed by triple quotes ("""). Each docstring should describe the purpose of the function, the function parameters, and what the function returns. Test your docstrings by calling help (getinputFile) and help (decrypt) in your main function. Be sure to include a docstring at the top of each of your function definitions. In Python, docstrings are located on the line directly after def function_name (param1, ...) : and is indented one level. The docstring may be one line or many lines, but must be enclosed by triple quotes ("""). Each docstring should describe the purpose of the function, the function parameters, and what the function returns. Test your docstrings by calling help (getinputFile) and help(decrypt) in your main function. Partial Sample Run 1 (does not show output from help calls): Enter the input filename: secretMessagel Invalid filename extension. Please re-enter the input filename: secretMessagel.jpg Invalid filename extension. Please re-enter the input filename: secretMessagel.txt The decrypted message is: congratulations Partial Sample Run 2 (does not show output from help calls): Enter the input filename: secretMessage2.txt The decrypted message is: i came i saw i conquered 6 IGSK O YGC 0 IUTWAKXKJ 18 UgFYj SLMDs LAGFKStep by Step Solution
There are 3 Steps involved in it
Step: 1
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
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started