Task 1: 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. (LO: 4.1, 4.2)
Task 1: 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. (LO: 4.1, 4.2)
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Alert dont submit

Transcribed Image Text:Task 1: 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. (LO: 4.1, 4.2)
![encrypt.py X
➜ encrypt.py
1 ✓ def caesar_cipher (plaintext, distance):
2
encrypted_text =
3 ✓
for char in plaintext:
4
5
6
7
8
HARGAINEAN
9
10
11
12
13
14 plaintext = input ("Enter the plaintext: ")
distance = int (input("Enter the distance value: "))
16 encrypted_text = caesar_cipher (plaintext, distance)
15
18
17 print("The encrypted line would be:", "[{}]" .format(encrypted_text)) # Adjusted output format
19
20
21
22
23
24
25
ascii_val = ord (char)
shifted_val = ascii_val + distance
# Ensure the shifted value falls within the printable ASCII range
if shifted_val > 126:
26
shifted_val -= 95
elif shifted_val < 32:
shifted_val += 95
encrypted_text += chr(shifted_val)
return encrypted_text
27
PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS
La c
Enter the plaintext: abcde
Enter the distance value: 127
The encrypted line would be: [
= Companion X
encrypted text using a Caesar cipher. The script should work for any printable characters. (LO: 4.1, 4.2)
Test Feedback:
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-02-08 01:22:37.812169
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 a line of code to encrypt: Enter a distance value: The encrypted line would be: "#$%&'
Error: AssertionError - Unable to find `abcde in the program's output.
Timestamp: 2024-02-08 01:22:37.836483
Your current grade is: 50.00%
RUN CODE
CALCULATE GRADE
→.../9780357881019-fundamentals-of-python-3e-6f0a5b7e-d091-4bbb-b58f-f28d396040cf/chapter4/ex01/student (template) $ python /workspaces/9780357881019-fundamentals-of-python-3e-6f0a5b7e-d091-4bbb-b58f-f28d396040cf/chapter4/ex01/student/encrypt.py
SUBMIT
I
B
↑
+✓ ...
bash
Program O..
>](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F75c91924-18a0-4f61-ad5f-a555275bbbab%2Fe423608f-c73e-4d3e-bf6f-640f2da2e9da%2Fxv7tgx_processed.png&w=3840&q=75)
Transcribed Image Text:encrypt.py X
➜ encrypt.py
1 ✓ def caesar_cipher (plaintext, distance):
2
encrypted_text =
3 ✓
for char in plaintext:
4
5
6
7
8
HARGAINEAN
9
10
11
12
13
14 plaintext = input ("Enter the plaintext: ")
distance = int (input("Enter the distance value: "))
16 encrypted_text = caesar_cipher (plaintext, distance)
15
18
17 print("The encrypted line would be:", "[{}]" .format(encrypted_text)) # Adjusted output format
19
20
21
22
23
24
25
ascii_val = ord (char)
shifted_val = ascii_val + distance
# Ensure the shifted value falls within the printable ASCII range
if shifted_val > 126:
26
shifted_val -= 95
elif shifted_val < 32:
shifted_val += 95
encrypted_text += chr(shifted_val)
return encrypted_text
27
PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL PORTS
La c
Enter the plaintext: abcde
Enter the distance value: 127
The encrypted line would be: [
= Companion X
encrypted text using a Caesar cipher. The script should work for any printable characters. (LO: 4.1, 4.2)
Test Feedback:
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-02-08 01:22:37.812169
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 a line of code to encrypt: Enter a distance value: The encrypted line would be: "#$%&'
Error: AssertionError - Unable to find `abcde in the program's output.
Timestamp: 2024-02-08 01:22:37.836483
Your current grade is: 50.00%
RUN CODE
CALCULATE GRADE
→.../9780357881019-fundamentals-of-python-3e-6f0a5b7e-d091-4bbb-b58f-f28d396040cf/chapter4/ex01/student (template) $ python /workspaces/9780357881019-fundamentals-of-python-3e-6f0a5b7e-d091-4bbb-b58f-f28d396040cf/chapter4/ex01/student/encrypt.py
SUBMIT
I
B
↑
+✓ ...
bash
Program O..
>
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education