Warning! It seems that you are using Dodona within another webpage, so not everything may work properly. Let your teacher know so that he can solve the problem by adjusting a setting in the learning environment. In the meantime, you can click this link to open Dodona in a new window.
Warning! The page was not fully loaded, probably because of a network issue. It could be that not all functionalities work as expected. Please try reloading the page.
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)