Question
PYTHON: ] Method1. Start by creating a function decrypt_caesar that takes in a message as a parameter. 2. Add a docstring to your function explaining
PYTHON:
] Method1. Start by creating a function decrypt_caesar that takes in a message as a parameter.
2. Add a docstring to your function explaining what the input to the function is and what yourdesired output is (decrypted files implementing different keys).
3. Create a for loop to iterate through the length of the alphabet where our iterator is defined askey. (We will be trying each shift value as a key to try to break our intercepted message).
4. Create an empty list named translated that will store each character as you apply a new key.
5. Create a for loop to iterate over each character in the message.
6. Check to see if the current character is a part of the alphabet, if it is then complete thefollowing stepsa) Create a new variable named num and set it equal to the ordinal of the uppercaseversion of our current character minus the ordinal of A.b) Utilize the minus-equals operator to subtract the key from num.c) If num is less than zero then utilize the plus-equals operator to add 26 to num.d) If our current character is lowercase then append the lowercase character of num plus theordinal of a to translated. Otherwise (if it is uppercase) append the character of numplus the ordinal of A to translated.
7. If our character is not part of the alphabet then append the character to translated.
8. Once we are done processing the message with our current key, join the characters in the arraytogether with .
9. Save the output to the file utilizing the following codefilename = f'decrypted_message_{key}.txt'with open(filename, 'w') as f:f.write(decrypted_message)Note: This will create a new file with our decrypted message for every key, so you will need toexamine the files to get the appropriate decrypted message.
10. Create a new function called retrieve_data which takes file_name as a parameter. Add adocstring to your function describing what the desired input and output is.
11. Open the provided file to read and then return a string containing the contents of the file.
12. Create a new function called main with no parameters.
13. Inside main, create a new variable called data which is equal to the invocation of ourretrieve_data function where the name of the encrypted file (intercepted_comm00.txt) as ouractual parameter (input).
14. Invoke our decrypt_caesar function passing in the variable data as our actual parameter(input).
15. Invoke main (there should be no output to the terminal, just files created in the directory yourun the file.
Note: If you receive an error at this point, then check to see if the file is in the appropriatedirectory.
Step 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