Skip to content

Caesar cipher

Caesar cipher

The Roman historian Suetonius wrote that Julius Caesar hid his messages by shifting each letter three places along the alphabet.

alphabet.index(ch) gives a letter's position, from 0 for a to 25 for z. Add the shift and use % 26, so that position 26 wraps back to 0. To decode a message, shift it again by 26 minus the original shift.

Log in or create account

IGCSE, A-Level & AP