Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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' 
  1. 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

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions

Question

Let f(x) = 3/64 x16 x2 for 0 Answered: 1 week ago

Answered: 1 week ago

Question

Draft a proposal for a risk assessment exercise.

Answered: 1 week ago