Question: def caesar _ cipher ( plaintext , distance ) : encrypted _ text = for char in plaintext: ascii _ val = ord

def caesar_cipher(plaintext, distance):
encrypted_text =""
for char in plaintext:
ascii_val = ord(char)
shifted_val = ascii_val + distance
# Ensure the shifted value falls within the printable ASCII range
if shifted_val >126:
shifted_val -=95
elif shifted_val <32:
shifted_val +=95
encrypted_text += chr(shifted_val)
return encrypted_text
plaintext = input("Enter the plaintext: ")
distance = int(input("Enter the distance value: "))
encrypted_text = caesar_cipher(plaintext, distance)
print("Encrypted text: ", encrypted_text)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!