Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON Programming. Please use comments to explain, thank you! In cryptography,

ID: 3789053 • Letter: P

Question

PYTHON Programming. Please use comments to explain, thank you!

In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3,D would be replaced by A, E would become B, and so on.

Caesar cipher

Encrypt an input string of lowercase letters (plaintext, first input) and prints the result. The other input is the distance value (distance).

Explanation / Answer

def encrypt(n, text):
res = ''
ref= 'abcdefghijklmnopqrstuvwxyz'

for m in text.lower():
try:
i = (ref.index(m) + n) % 26
res += ref[i]
except ValueError:
res += m
return res.lower()

we take text and distance n as input , iterate over the alphabets in string and encrypt each character using the expression finally return result