Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON QUESTION (e.1) Write the two functions shift_encrypt and shift_decrypt . Each takes two arguments: a string containing the message (the plaintext for encryption, the

PYTHON QUESTION

(e.1) Write the two functions shift_encrypt and shift_decrypt. Each takes two arguments: a string containing the message (the plaintext for encryption, the ciphertext for decryption) and an int for the key, indicating how far down the alphabet to find each substitute letter. The encryption function returns the ciphertext; the decryption function returns the plaintext.

As always, follow the design recipe. In particular make up enough examples to test both your understanding of the functions' behavior and the match between your code and that behavior. Here are two more details: In the plaintext, turn any upper-case letters into lower-case letters. In both the plaintext and the ciphertext, leave non-letters unchanged.

With the right tools, each function can be written in two lines of code (plus function headers and docstrings). Think for a while about how to write this; if you're still stuck, you may wish to consult these hints (one at a time): (i) It's convenient to have a global constant called ALPHABET that contains all 26 lower-case letters in order. (ii) To do the work, you'll want to use the translate() method; look it up to make sure you understand how to use it. Seeing what arguments it takes may suggest some of the things you need to compute. (iii) It would also be convenient to have a function that takes a number and produces a "rotated" alphabet with the specified number of characters taken off the front and added on to the end of the string.

Okay, it's time. Write the functions and test them.

(e.2) Each partner should do this part independently: Make up a message without telling your partner what it is. Encrypt the message with a key of your choosing. Copy the encrypted message into an Email message and send it to your partner; put the key in the subject line[*]. When you receive the Email your partner sent you, decrypt it using the key you received.

[*] It is not good security to include the key with the message. Of course that doesn't matter to us here in lab. But in real life, this would be like writing your PIN on your ATM card. Key distribution is an issue in modern cryptography; you need a secure and independent way to get the key to the intended recipient of the ciphertext.

(e.3) If you have time, you could check that the key is in the correct range (0 to 25) or, better yet, make keys greater than 25 "wrap around" so that, for example, shift_encrypt("cat", 29) returns the same thing as shift_encrypt("cat", 3). (Hint: Use the % (mod) operator.)

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

How do e-businesses generate revenue streams?

Answered: 1 week ago

Question

Find f. f"(x) = x 2 , x > 0, f(1) = 0, f(2) = 0

Answered: 1 week ago

Question

Is conflict always unhealthy? Why or why not? (Objective 4)

Answered: 1 week ago