Built and fact-checked by the DocNectar team — see our editorial standards
Key Features
Instant Calculation
Get accurate results in real time with our optimized algorithm.
Mobile Friendly
Fully responsive design. Works on all devices & screen sizes.
Privacy Focused
Your data stays on your device. We don't store any inputs.
100% Free
No hidden costs. This tool is completely free forever.
The affine cipher generalizes the Caesar cipher by combining a multiplication step with a shift step, giving a much larger set of possible keys than a simple shift alone.
This tool encrypts or decrypts text using an affine cipher with two keys you choose: a multiplier (a) and a shift (b).
How it works
Enter your text along with two numbers: a (which must share no common factor with 26 — valid choices are 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, or 25) and b (any number from 0 to 25). To encrypt, each letter's position is multiplied by a, then b is added, wrapping mod 26. To decrypt, the reverse math uses the modular inverse of a. Non-letter characters are left unchanged.
- Enter mode.
- Enter text.
- Enter a (must be coprime with 26, e.g. 5).
- Enter b (0-25).
- Click Calculate to see your results.
Examples
a = 5, b = 8
"Attack at dawn" encrypted with a = 5 and b = 8 becomes "Izzisg iz xiov".
Who should use it
- Teaching modular arithmetic and substitution ciphers.
- Puzzle and escape-room style word games with a bit more complexity than Caesar.
Industry applications
- Cryptography education
- Games and puzzles
Advantages
- Larger key space than a plain Caesar shift (312 combinations vs. 25).
- A useful next step for learning modular arithmetic in cryptography.
Limitations
- Still trivially breakable with modern computing — no real security.
Common mistakes to avoid
- Picking a value for a that isn't coprime with 26 (like 2, 4, or 13) — the tool will reject these since they can't be reversed.
- Forgetting that both a and b must match exactly between encryption and decryption.
Best practices
- Use the affine cipher for puzzles or to explore how combining a shift with a multiplication changes a classical cipher — not for protecting real secrets.
Tips
- If decryption doesn't produce readable text, double check that a and b exactly match the values used for encryption.