Caesar cipher
Sign in to test your solution.
# Caesar cipher program
# -------------------------
# Subprograms
# -------------------------
def encrypt_message(message):
key = 5
encrypted_message = ""
for character in message:
ascii_code = ord(character)
ascii_code = ascii_code + key
if ascii_code > 126:
ascii_code = 32 + ascii_code - 127
encrypted_message = encrypted_message + chr(ascii_code)
return encrypted_message
# -------------------------
# Main program
# -------------------------
actual_message = input("Enter a message: ")
stored_message = encrypt_message(actual_message)
print("Message to send:", stored_message)
You can submit as many times as you like. Only your latest submission will be taken into account.
Sign in to test your solution.
Python sandbox
This window allows you to run Python code without installing a thing. The code you write here is not automatically submitted to Dodona.