Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a script in the file encrypt.py that inputs a line of plaintext and a distance value and outputs an encrypted text using a Caesar

Write a script in the file encrypt.py 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.
def caesar_cipher(text, shift):
encrypted_text =''
for char in text:
# Shift each character by 'shift' positions
shifted_char = chr((ord(char)+ shift)%256)
encrypted_text += shifted_char
return encrypted_text
if __name__=="__main__":
# Input from user
plaintext = input("Enter the plaintext: ")
distance = int(input("Enter the distance value: "))
# Encrypting the plaintext
encrypted_text = caesar_cipher(plaintext, distance)
print("Encrypted text:", encrypted_text)
Status: PASSED!
Check: 1
Test: Program outputs correct values when user inputs message and distance of 2
Reason: 'cdefgh' was found in the program's output.None
Timestamp: 2024-03-1719:44:16.518709
Status: FAILED!
Check: 2
Test: Program outputs correct values when user inputs message and distance of 127
Reason: Unable to find '['`abcde']' in the program's output.
Enter the plaintext: Enter the distance value: Encrypted text:
.
Error : AssertionError - Unable to find `abcde in the program's output.
Timestamp: 2024-03-1719:44:16.536100
pls revise my python code

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

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago