Write a script that inputs a line of plaintext and a distance value and outputs
ID: 3889672 • Letter: W
Question
Write a script that inputs a line of plaintext and a distance value and outputs an encrypted text using a Caesar cipher. The script should work for any printable characters.
Here are what the expexted results are supposed to be. This is an activity from MindTap. Thank you
MINDTAP From Cengage Strings and Text Files (Exercise 1) Due on Sep 26 at 11:59 PM EDT encrypt.py 1# Prompt user to enter a message Write a script that inputs a line of plaintext and a distance value and outputs an encrypted text using a Caesar cipher. The script should work for any printable characters 3# Prompt user to enter a shift 4 | 5 # Print the encrypted messageExplanation / Answer
def caesar(plainText, shift):
cipherText = ""
for char in plainText:
newChar = ord(char) + shift
if newChar > 128:
newChar = newChar % 128
finalChar = chr(newChar)
cipherText += finalChar
return cipherText
text = input("Enter plain text: ");
s = input("Shift: ");
print (caesar(text, int(s)));
Chk this once and let me know
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.