Skip to content

04-10: Caesar Cipher

Python: Fundamentals

View the live site — ijk37.com

Project 10

Home  |  All Projects  |  Notes  |  Exercises  |  Quiz Hub

Encrypts and decrypts messages using the Caesar cipher (letter-shifting). Also includes a brute-force mode that prints all 25 possible decryptions when the shift is unknown.

Topics covered: ord() / chr() · modular arithmetic · str.isalpha() · str.islower() · functions · for loop · while-loop menu

Difficulty: ⭐ Beginner


How to Run

python main.py

Sample Output

Encrypted (shift 3):
  Khoor, Zruog!

Brute-force (shift 3 found at row 3):
  Shift    Decrypted text
  1        Jgnnq, Yqtnf!
  2        Ifmmp, Xpsme!
  3        Hello, World!   ← readable!
  ...

Key Concepts Practised

Concept Where used
ord(char) - ord('a') Convert letter → 0-based index
% ALPHABET_SIZE Wrap-around (Z+1 → A)
chr(base + shifted) Convert index back → letter
Preserving case Choosing ord('a') vs ord('A') as base
Non-letter pass-through if char.isalpha() guard