The Caesar Cipher is one of the earliest known substitution ciphers, originally used byJulius Caesar around 58 BC to protect secret military communications across the Roman Empire.
The Mathematical Formulation
In cryptography, we convert each letter of the alphabet into an integer from 0 to 25:
A=0, B=1, C=2, ..., X=23, Y=24, Z=25
Given an integer letter position $x$ and a secret Key Code $k$ ($1 \le k \le 25$):
Encryption:E_k(x) = (x + k) mod 26
Decryption:D_k(y) = (y - k) mod 26
Why the Modulo Operator (mod 26)?
The modulo operation (remainder after division, or % in code) creates a circular alphabet. If you shift the letter Z (position 25) forward by +3:
(25 + 3) = 28 → 28 mod 26 = 2 → Letter 'C'
The remainder naturally loops back to the start of the alphabet so letters never run off the end!
Security Fun Fact: Because there are only 25 possible shifts in the English alphabet, this cipher can be easily cracked by testing every shift ("brute-force attack"). However, it forms the foundational building block for modern ciphers and modular cryptography!