Amina is writing a Python program to encrypt messages using a Caesar cipher.
The Caesar cipher works by shifting each letter of a message forward in the alphabet by a set number of places (the key).
For example, with a key of +3, the word code becomes frgh:
| Plaintext | c | o | d | e |
|---|---|---|---|---|
| Ciphertext | f | r | g | h |
Amina has already written the helper function encrypt(text, key) which performs the character shifting.
She needs you to complete the rest of the program to meet these requirements:
encrypt function with the plaintext and valid key to generate the ciphertext.secret.txt.Complete the Python 3 program code below:
def encrypt(text, key):
ciphertext = ""
for char in text:
if char.isalpha():
start = ord('a') if char.islower() else ord('A')
ciphertext += chr((ord(char) - start + key) % 26 + start)
else:
ciphertext += char
return ciphertext
# --- COMPLETE THE PROGRAM BELOW THIS LINE ---