I am currently trying to write a program, for school, in order to encrypt and decrypt a inputted message. I need the encrypted or decrypted message to only be in the alphabet no other symbols or keys, for example, with an inputted offset of 5 using the message van to encrypt, i want it to output 'afs'. Can anyone help please? This is my code currently.
def find_offset():
offset = int(input("Enter an offset: "))
if offset > 25 or offset < 0:
print("Invalid offset, please enter another offset: ")
find_offset()
else:
print("Okay")
encrypt_fun(offset)
def encrypt_fun(offset):
choice = ''
while choice != '3':
choice = input("\nDo you want to encrypt or decrypt the message?\nEnter 1 to Encrypt, 2 to Decrypt, 3 to Exit Program: ")
if choice == '1':
message = input("\nEnter the message to encrypt: ")
for i in range(0, len(message)):
result = chr(ord(message[i]) + offset)
print(result, end=''),
elif choice == '2':
message = input("\nEnter the message to decrypt: ")
for i in range(0, len(message)):
result = chr(ord(message[i]) - offset)
print(result, end=''),
elif choice != '3':
print("You have entered an invalid choice. Please try again.\n\n")
find_offset()