I am currently trying to write a program, for school, in order to encrypt and decrypt a inputted message. My code currently works but it is not fully complete. I am having trouble trying to allow it to enter an offset from values from 2-26 and I am having trouble making it repeat the question then carry on with the code until it gets the correct value. Right now it just says invalid message when a wrong number is entered but still carries on with the code. Also I need the encrypted or decrypted message to only be in the alphabet no other symbols or keys. Can anyone help please? This is my code currently.
result = ''
message = ''
choice = ''
offset=int(input("Enter an offset: "))
if offset >25 or offset <0:
print("Invalid offset, please enter another offset: ")
else:
print("Okay")
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 = result + chr(ord(message[i]) - offset)
print (result + '\n\n')
result = ''
elif choice == '2':
message = input("\nEnter the message to decrypt: ")
for i in range(0, len(message)):
result = result + chr(ord(message[i]) + offset)
print (result + '\n\n')
result = ''
elif choice != '3':
print ("You have entered an invalid choice. Please try again.\n\n")