Read this lesson as text
Affine Cipher
Cryptography · Axiom Academy
Learn how linear functions create a powerful substitution cipher in cryptography The Affine Cipher uses a linear function to map plaintext letters to ciphertext letters. Each letter is first converted to a number (A=0, B=1, ..., Z=25), then the encryption function is applied. a = multiplicative key (must be coprime with 26) E(x) = encrypted letter (0-25) 2. The Coprimality Requirement For the Affine Cipher to work properly, the multiplicative key a must be coprime with 26. This means gcd(a, 26) = 1, which ensures every plaintext letter maps to a unique ciphertext letter (making decryption possible). Total key space: 12 choices for a × 26 choices for b = 312 possible keys To decrypt an Affine Cipher, we need to reverse the encryption function. This requires finding the modular multiplicative inverse of the key a . a -1 = modular multiplicative inverse of a mod 26 D(y) = decrypted letter (0-25) Let's encrypt the word "MATH" using the Affine Cipher with keys a = 5 and b = 8. E(12) = (5 × 12 + 8) mod 26 = 68 mod 26 = 16 → Q E(0) = (5 × 0 + 8) mod 26 = 8 mod 26 = 8 → I E(19) = (5 × 19 + 8) mod 26 = 103 mod 26 = 25 → Z E(7) = (5 × 7 + 8) mod 26 = 43 mod 26 = 17 → R Now let's decrypt "QIZR" back to "MATH" using a = 5 and b = 8. We need: (5 × a -1 ) mod 26 = 1 Testing: 5 × 21 = 105 = 4 × 26 + 1, so a -1 = 21 D(16) = 21 × (16 - 8) mod 26 = 21 × 8 mod 26 = 168 mod 26 = 12 → M D(8) = 21 × (8 - 8) mod 26 = 21 × 0 mod 26 = 0 → A
This is the written version of the interactive lesson above. See the full Cryptography course.