print("Select mode: encrypt or decryptn")
prompt_mode = input("e/d: ").lower()
message = input("Enter message to encrypt: ").lower()
shift = int(input("Enter shift value: "))
def message_enc(message, shift):
if prompt_mode == "e":
e_message = ""
for char in message:
if char.islower():
e_message += chr((ord(char) + shift - 97) % 26 + 97)
else:
e_message += char
return e_message
print(message_enc(message, shift))
def message_dec(message, shift):
if prompt_mode == "d":
d_message = ""
for char in message:
if char.islower():
d_message += chr((ord(char) - shift - 97) % 26 + 97)
else:
d_message += char
return d_message
print(message_dec(message, shift))
output of message_enc
is has all characters together and I can’t seem to find a way to keep the spaces between the words. Also, how can I make the program stop so that once it prints message_enc
it doesn’t go to the next line of code?
I have tried adding a for loop to check if char
is ” ” and just add it to enc_message
as is, but still no luck.