Caesar Cipher
Solved Examples with Detailed Step-by-Step Explanation
Encryption Decryption Brute Force Key Analysis
Classical Cryptography | Substitution Cipher
What is the Caesar Cipher?
Definition: The Caesar Cipher is one of the oldest and simplest encryption techniques. It is a substitution
cipher where each letter in the plaintext is shifted by a fixed number of positions down the alphabet.
Named After Type Key
HISTORY CIPHER TYPE SECRET KEY
Julius Caesar used it to protect Monoalphabetic substitution cipher A single integer (0–25) representing
military messages with a shift of 3 — one-to-one letter mapping the number of positions to shift
Encryption: E(x) = (x + k) mod 26 Decryption: D(x) = (x − k + 26) mod 26
Alphabet Shift Visualization (Key = 3)
Plaintext: A B C D E F G H I J K L M N O P Q R S T U V W
Ciphertext: D E F G H I J K L M N O P Q R S T U V W X Y Z
← Each letter shifts right by 3 positions →
Wrap-Around: Letters near the end of the alphabet wrap around. X → A | Y → B | Z → C
Letter → Number Mapping (for formula use):
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Example 1: Encryption | Plaintext: "HELLO" | Key: 3
Problem: Encrypt the word "HELLO" using Caesar Cipher with key k = 3
Step-by-Step Solution:
Letter Position (x) Formula (x+3) mod 26 Result Position Ciphertext Letter
H 7 (7 + 3) mod 26 = 10 10 K
E 4 (4 + 3) mod 26 = 7 7 H
L 11 (11 + 3) mod 26 = 14 14 O
L 11 (11 + 3) mod 26 = 14 14 O
O 14 (14 + 3) mod 26 = 17 17 R
Result: HELLO → KHOOR (Key = 3)
Example 2: Decryption | Ciphertext: "KHOOR" | Key: 3
Problem: Decrypt the word "KHOOR" using Caesar Cipher with key k = 3 Formula: D(x) = (x − k + 26) mod 26
Step-by-Step Solution:
Cipher Letter Position (x) Formula (x−3+26) mod 26 Result Position Plaintext Letter
K 10 (10 − 3 + 26) mod 26 = 7 7 H
H 7 (7 − 3 + 26) mod 26 = 4 4 E
O 14 (14 − 3 + 26) mod 26 = 11 11 L
O 14 (14 − 3 + 26) mod 26 = 11 11 L
R 17 (17 − 3 + 26) mod 26 = 14 14 O
Result: KHOOR → HELLO (Successfully Decrypted! ✓)
Example 3: Wrap-Around Case | Plaintext: "XYZ" | Key: 4
Problem: Encrypt "XYZ" with key k = 4. Note: letters wrap around from Z back to A (modular arithmetic).
Step-by-Step Solution:
Letter: X (pos = 23) Letter: Y (pos = 24) Letter: Z (pos = 25)
(23 + 4) mod 26 (24 + 4) mod 26 (25 + 4) mod 26
= 27 mod 26 = 1 = 28 mod 26 = 2 = 29 mod 26 = 3
→ B → C → D
Wrap-Around Logic: When (x + k) ≥ 26, subtract 26. Example: 27 mod 26 = 1 → B
Result: XYZ → BCD
Example 4: Encrypt Full Sentence | Key: 13 (ROT13)
Problem: Encrypt "ATTACK AT DAWN" with key k = 13 (ROT13: special case where encryption = decryption)
Plain Pos +13 mod 26 Cipher Plain Pos +13 mod 26 Cipher ROT13
Fun Fact
A 0 13 13 N A 0 13 13 N
T 19 32 6 G T 19 32 6 G
With k=13:
Encrypt(Encrypt(x)) = x
T 19 32 6 G D 3 16 16 Q
Applying ROT13 twice returns
A 0 13 13 N A 0 13 13 N the original text!
C 2 15 15 P W 22 35 9 J Self-inverse cipher
K 10 23 23 X N 13 26 0 A
ATTACK AT DAWN → NGGNPX NG QNJA
Example 5: Brute Force Attack | Ciphertext: "ROVVY"
Problem: Unknown key. Try all 25 possible shifts to decrypt "ROVVY" and find the meaningful English word.
All 25 Possible Decryptions:
k=1: QNUUX k=2: PMTTW k=3: OLSSV k=4: NKRRU k=5: MJQQT
k=6: LIPPS k=7: KHOOR k=8: JGNNQ k=9: IFMMP k=10: HELLO
k=11: GDKKN k=12: FCJJM k=13: EBIIL k=14: DAHHK k=15: CZGGJ
k=16: BYFFI k=17: AXEEH k=18: ZWDDG k=19: YVCCF k=20: XUBBE
k=21: WTAAD k=22: VSZZC k=23: URYYB k=24: TQXXA k=25: SPWWZ
Key = 10 → ROVVY → HELLO ← Meaningful English word! (Correct Key Found ✓)
Caesar Cipher: Strengths & Weaknesses
✓ STRENGTHS ✗ WEAKNESSES
✓ Simple to understand and implement ✗ Only 25 possible keys — easily brute-forced
✓ Fast encryption and decryption ✗ Vulnerable to frequency analysis attacks
✓ Works well as an introduction to cryptography ✗ No real security for modern use cases
✓ Easy to apply manually without a computer ✗ Same letter always maps to same cipher letter
✓ Only requires a single number (key) to be shared ✗ Key distribution is not secure
Modern Alternatives: AES (Advanced Encryption Standard), RSA, and other modern ciphers address all of Caesar's
weaknesses and provide real-world security. Caesar Cipher is used today only for educational purposes.
Summary
1 Caesar Cipher shifts each letter by a fixed key (0–25) 4 Letters wrap around: Z + 1 = A (modular arithmetic)
2 Encryption: E(x) = (x + k) mod 26 5 ROT13 (k=13) is self-inverse — decrypt = encrypt
3 Decryption: D(x) = (x − k + 26) mod 26 6 Only 25 keys — vulnerable to brute force attacks
Caesar Cipher · Classical Cryptography · Substitution Cipher