0Pricing
Cryptology Academy · Lesson

Caesar Cipher Mechanics

Implement and break the classic ROT-N substitution cipher.

Caesar Cipher Mechanics is a free Cryptology Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cryptology Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Welcome

The Caesar cipher is the simplest substitution cipher. Each letter is shifted by a fixed number of positions in the alphabet. Let's implement and break it.

How Caesar Cipher Works

With shift 3: A→D, B→E, ..., Z→C. 'HELLO' becomes 'KHOOR'. Decryption shifts back: 'KHOOR' becomes 'HELLO'.

Mathematical Definition

Encryption: E(x) = (x + k) mod 26. Decryption: D(y) = (y - k) mod 26. Here x is the letter index (A=0) and k is the shift key.

ROT-13 Variant

ROT-13 is a Caesar cipher with shift=13. Since 13+13=26, encryption and decryption are the same function. It is used on forums to hide spoilers.

Python Encryption

def caesar(text, k): result = '' for c in text.upper(): if c.isalpha(): result += chr((ord(c) - 65 + k) % 26 + 65) else: result += c return result print(caesar('HELLO', 3)) # KHOOR

Python Decryption

Decryption is just encryption with a negative shift: def decrypt(text, k): return caesar(text, -k) print(decrypt('KHOOR', 3)) # HELLO

Breaking Caesar by Brute Force

There are only 25 possible shifts. An attacker simply tries all 25 and picks the result that looks like English. No computer needed — seconds by hand.

Key Space Analysis

Key space = 26 (or 25 excluding identity). Compare to AES-128 with 2^128 ≈ 3.4×10^38 keys. The Caesar cipher key space is catastrophically small.

Frequency Analysis Preview

Even without brute force, frequency analysis works: 'E' is the most common letter in English (~13%). Find the most frequent ciphertext letter and guess the shift.

ROT-N in Real Code

Python: import codecs; codecs.encode('hello', 'rot_13') gives 'uryyb'. ROT-13 is built into Python's codecs module, showing its historical relevance.

Caesar in Historical Context

Caesar used shift 3 for his private correspondence. Against illiterate adversaries it worked. Against educated opponents it was trivially broken by 800 CE.

Quick Check

What is the ciphertext of 'ABC' using a Caesar cipher with shift 3?

Recap

You've implemented and broken the Caesar cipher. Next, we'll explore more complex classical ciphers: Atbash and Affine.

Frequently asked questions

Is the “Caesar Cipher Mechanics” lesson free?

Yes — the full text of “Caesar Cipher Mechanics” is free to read here on the web, and the Cryptology Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cryptology Academy course, upgrade to CoddyKit PRO.

What will I learn in “Caesar Cipher Mechanics”?

Implement and break the classic ROT-N substitution cipher. You practise Cryptology Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cryptology Academy?

No prior experience is required. Cryptology Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Caesar Cipher Mechanics” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cryptology Academy lesson?

Yes. Every Cryptology Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Caesar Cipher Mechanics
  2. Atbash & Affine Ciphers
  3. Vigenère & Polyalphabetic Ciphers
  4. Frequency Analysis & Cryptanalysis Basics
← Back to Cryptology Academy