Affine Cipher Decoder & Calculator

Professional online tool for Affine cipher encryption and decryption with a mathematical formula calculator and step-by-step solver.

🚀 Quick Examples - Try These:

Affine Cipher Tool with Calculator

📝 Input Text
📤 Output Text
Slope Parameter (a) 5
Must be coprime to 26. Valid: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25
Intercept Parameter (b) 8
Range: 0-25 (shift amount in alphabet)
Custom Alphabet & Options
Analysis Options

Affine Cipher Examples with Solutions

Example 1: Basic Encryption

Plaintext: "HELLO" | Key: a = 5, b = 8

H → 7: E(7) = (5×7 + 8) mod 26 = 43 mod 26 = 17 → R E → 4: E(4) = (5×4 + 8) mod 26 = 28 mod 26 = 2 → C L → 11: E(11) = (5×11 + 8) mod 26 = 63 mod 26 = 11 → L L → 11: E(11) = (5×11 + 8) mod 26 = 63 mod 26 = 11 → L O → 14: E(14) = (5×14 + 8) mod 26 = 78 mod 26 = 0 → A

Ciphertext: "RCLLA"

Example 2: Decryption Process

Ciphertext: "MJQTO" | Key: a = 5, b = 8 (Inverse: a⁻¹ = 21)

M → 12: D(12) = 21×(12-8) mod 26 = 21×4 mod 26 = 84 mod 26 = 6 → G J → 9: D(9) = 21×(9-8) mod 26 = 21×1 mod 26 = 21 → V Q → 16: D(16) = 21×(16-8) mod 26 = 21×8 mod 26 = 168 mod 26 = 12 → M T → 19: D(19) = 21×(19-8) mod 26 = 21×11 mod 26 = 231 mod 26 = 23 → X O → 14: D(14) = 21×(14-8) mod 26 = 21×6 mod 26 = 126 mod 26 = 22 → W

Plaintext: "GVMXW"

Example 3: Finding Keys from Known Plaintext

Known: A→D, T→F

A(0) → D(3): 3 = (a×0 + b) mod 26 → b = 3 T(19) → F(5): 5 = (a×19 + 3) mod 26 2 = 19a mod 26 → a = 16 Key found: a = 16, b = 3

Complete Guide to the Affine Cipher

🧮 Mathematical Foundation

The Affine cipher uses linear algebra for encryption and decryption:

Encryption: E(x) = (ax + b) mod n
Decryption: D(x) = a⁻¹(x - b) mod n

Where 'a' must be coprime to n (gcd(a,n) = 1) to ensure the cipher is reversible.

🔑 Key Space Analysis

  • Valid 'a' values: 12 (numbers coprime to 26)
  • Valid 'b' values: 26 (any integer 0-25)
  • Total keys: 12 × 26 = 312 possible combinations
  • Security: Vulnerable to frequency analysis and brute force

⚡ Cryptanalysis Methods

  • Brute Force: Try all 312 possible keys
  • Frequency Analysis: Use letter frequency patterns
  • Known Plaintext: Use two known letter pairs to solve for a and b

🛡️ Security Considerations

  • Weakness: Preserves letter frequency patterns, making it insecure for modern use.
  • Vulnerability: Only 312 keys, easily breakable by computers.
  • Modern Use: Primarily for educational purposes and puzzles.

📈 Historical Context

  • Development: An extension of the Caesar cipher, adding multiplication.
  • Innovation: Introduced more complex mathematical concepts to classical ciphers.
  • Legacy: A key teaching tool for modular arithmetic in cryptography.

🎯 Practical Applications

  • Education: Teaching modular arithmetic and basic cryptographic principles.
  • Puzzles: Used in escape rooms and cryptographic challenges.
  • Programming: A good exercise for implementing algorithms.

Frequently Asked Questions

What is an Affine cipher and how does it work? +

The Affine cipher is a mathematical substitution cipher using the function E(x) = (ax + b) mod 26. It combines multiplication ('a') and addition ('b') to transform letters.

How do I decrypt an Affine cipher without knowing the key? +

You can use brute force (trying all 312 keys), frequency analysis, or use two known plaintext-ciphertext pairs to solve for the keys 'a' and 'b'.

Why must the slope value 'a' be coprime to 26? +

So the encryption function is reversible. If 'a' and 26 shared a factor, multiple letters would encrypt to the same letter, making unique decryption impossible.

What is the difference between Affine cipher and Caesar cipher? +

A Caesar cipher is an Affine cipher where a=1. The Affine cipher adds a multiplication step, increasing the key space from 25 to 312.

How do I find the multiplicative inverse for decryption? +

The inverse a⁻¹ mod 26 is a number that results in 1 when multiplied by 'a' mod 26. For example, the inverse of 5 mod 26 is 21 because 5 * 21 = 105 ≡ 1 (mod 26).

Can I use the Affine cipher with custom alphabets? +

Yes! Our tool supports custom alphabets. The modulus and valid slope values will adjust automatically based on the alphabet's length.

Is the Affine cipher secure for modern use? +

No. With only 312 keys and vulnerability to frequency analysis, it's easily broken. It is used for educational purposes.

What are some examples of Affine cipher in practice? +

Encoding "HELLO" with (a=5, b=8) gives "RCLLA". It is often used in cryptography courses, programming exercises, and puzzle games like escape rooms.