All lessons

Leveling up · step 22 of 22

Lab: the Caesar cipher

Sign in if you want this lab saved to your progress.

Hide a message the ancient way

Julius Caesar shifted every letter of a message a few places down the alphabet to keep it private. Build the encoder.

Write encode(message, shift) that returns a new string where every letter has moved shift places forward, wrapping from z back to a. Leave spaces and punctuation exactly as they are, keep capitals capitalised, and a shift of 0 returns the message unchanged.

Then print encode("attack at dawn", 3).

Getting started: ord(letter) gives a letter's number and chr(number) turns a number back into a letter. Letters run from ord('a') = 97 to ord('z') = 122, and % 26 is what wraps the alphabet around.

Build it

Fill in the code, then run it. Every check has to pass for the lab to count.

lab-caesar-cipher.py