Question
Can you help me with this Python Assignment? Write a function cipher(plaintext, n) to shift all characters in a string of text. Your function should
Can you help me with this Python Assignment?
Write a function cipher(plaintext, n) to shift all characters in a string of text. Your function should take 2 parameters, the plaintext to shift (a string) and the shift key n (an integer). Set up an accumulator variable (suggested name: ciphertext) in which to accumulate the result. Use a definite loop with the accumulator pattern to go through all characters in plaintext.
For each character, call your shift_char function to obtain the shifted version of that character, which you will concatenate into ciphertext. Return the ciphertext after the loop.
Here are some test cases:
>>> cipher('time', 4) 'xmqi' >>> cipher('welcome to the machine', 19) 'pxevhfx mh max ftvabgx'
- Suppose you have some ciphertext (i.e., 'iuet kag iqdq tqdq', or 'prqhb') but you dont know which decryption key (i.e., the number of characters to shift) to use. Write a function called codebreaker(ciphertext) that will try all possible Caesar cipher shifts (there are only 26 to try) and print out each possible deciphering. One of them will stand out as a valid English phrase. Your program must re-use your cipher function from question 2 above.
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