0Pricing
Cryptology Academy · Lesson

Atbash & Affine Ciphers

Explore Hebrew Atbash and the mathematical affine cipher.

Atbash & Affine Ciphers is a free Cryptology Academy lesson on CoddyKit — lesson 2 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

In this lesson we study Atbash, a Hebrew mirror cipher, and the Affine cipher, which applies a linear mathematical transformation to each letter.

Atbash Cipher

Atbash mirrors the alphabet: A↔Z, B↔Y, C↔X, ... It originates in Hebrew scripture (~600 BCE). The word 'Sheshakh' in Jeremiah is Atbash for 'Babel'.

Atbash Formula

For a 26-letter alphabet: E(x) = 25 - x. So A(0)→Z(25), B(1)→Y(24). The same function decrypts. It is its own inverse.

Atbash Python

def atbash(text): result = '' for c in text.upper(): if c.isalpha(): result += chr(90 - (ord(c) - 65)) else: result += c return result print(atbash('HELLO')) # SVOOL

Affine Cipher Concept

The Affine cipher uses: E(x) = (a*x + b) mod 26. The key is the pair (a, b). Caesar is a special case with a=1.

Affine Key Constraint

The multiplier 'a' must be coprime to 26 (gcd(a,26)=1). Valid values: 1,3,5,7,9,11,15,17,19,21,23,25. If gcd(a,26)≠1, decryption is impossible.

Affine Decryption

D(y) = a_inv * (y - b) mod 26, where a_inv is the modular inverse of a. For a=5: 5*a_inv ≡ 1 (mod 26) → a_inv = 21.

Affine Python

from math import gcd def affine_enc(x, a, b): return (a*x + b) % 26 def mod_inv(a, m): for i in range(1, m): if (a*i) % m == 1: return i def affine_dec(y, a, b): ai = mod_inv(a, 26) return (ai * (y - b)) % 26

Total Affine Key Space

There are 12 valid values of 'a' and 26 values of 'b', giving 12×26 = 312 possible keys. Still trivially small — brute-force in microseconds.

Affine vs Caesar Security

Affine ciphers are stronger than Caesar (312 vs 25 keys) but remain vulnerable to frequency analysis since each plaintext letter always maps to the same ciphertext letter.

Monoalphabetic Substitution Limit

Any cipher with a fixed substitution alphabet is called monoalphabetic. All are broken by frequency analysis. We need polyalphabetic ciphers to improve.

Quick Check

For the Affine cipher with a=5, b=8: what is E(0) (encrypting letter A)?

Recap

You've mastered Atbash and Affine ciphers. Next we'll tackle the Vigenère cipher — the first major step beyond monoalphabetic substitution.

Frequently asked questions

Is the “Atbash & Affine Ciphers” lesson free?

Yes — the full text of “Atbash & Affine Ciphers” 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 “Atbash & Affine Ciphers”?

Explore Hebrew Atbash and the mathematical affine 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 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Atbash & Affine Ciphers” 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