CS 100

Logo

Scientific Computing

Activity 16 - The Caesar cipher

Encryption often involves the Caesar cipher - named after Julius Caesar, who used the system to encrypt military messages. Many early internet users also adopted this cipher. Called rot13, the cipher encrypts a message by rotating the plaintext character by 13 positions in the alphabet. For example, “a” becomes “n” and likewise “n” becomes “a”. The nice thing about rot13 is that the same function can be used to encrypt and decrypt a message!

  1. Create a file called caesar.py. Write a function called rot13 that takes a message as a parameter and rotates all alphabet characters by 13 places and preserves whitespace characters.
    def rot13(msg):
       # your code here
       result = ""
       
       return result
    
  2. Use your function to decrypt the following message: "lbh ner n fhcre pbby pbqr oernxvat clguba cebtenzzre". Print the decrypted message.

If you finish early

  1. Create an encrypted message of your own with the Caesar cipher.
  2. Decrypt your encrypted message.

Submit your working caesar.py to Moodle.