External Exam Download Resources Web Applications Games Recycle Bin

Caeser Cipher

caesercipher.py

# Caesar / substitution cipher (symmetric encryption)

plain_text = "DigitalSolutions"
secret_key = +3 #shift of three..

# could improve this by writing rules to
# shift X >> A, y >> b, Z >> C, etc:

cipher_text = ""
for letter in plain_text:
    cipher_text += chr(ord(letter) + secret_key)
    #D becomes G, i becomes l, g becomes j, etc
print("Encrypted message:", cipher_text)

decrypted_msg = ""
for letter in cipher_text:
    decrypted_msg += chr(ord(letter) - secret_key)
print("Decrypted message:", decrypted_msg)