The Caesar cipher shifts every letter by the same fixed amount — simple, but also simple to break. The Affine cipher generalizes that idea with actual modular arithmetic: each letter’s position is multiplied by a key before the shift is applied, which is why getting the math right (and choosing a valid key) matters more than it might first appear.
What Is the Affine Cipher Tool?
Enter two keys — A (which must be coprime with 26) and B (a simple shift amount) — along with your text, and the tool applies the formula E(x) = (a·x + b) mod 26 to every letter. It automatically warns you if your chosen A value isn’t valid for decryption, and computes the correct modular inverse behind the scenes when decrypting.
How to Use It
- Open the tool at /tools/affine-cipher.
- Type your text.
- Set key A (must be one of 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25) and key B (0-25).
- Click “Encrypt” or “Decrypt”.
- Copy the result.
Key Features
- Automatic key validation — warns immediately if A isn’t coprime with 26, which would make decryption impossible.
- Correct modular inverse calculation for decryption, computed automatically behind the scenes.
- Generalizes the Caesar cipher — setting A=1 reproduces standard Caesar-cipher behavior exactly.
- Matches the well-known A=5, B=8 reference example exactly.
When to Use This Tool
- Learning how modular arithmetic underlies classical substitution ciphers.
- Understanding why cipher key choices matter mathematically, not just as arbitrary numbers.
- Solving or building cryptography puzzles that use the Affine cipher.
Try It Now
Open Affine Cipher directly, or press ⌘K and type the tool name from anywhere on the site.
Part of the Security & Crypto collection on WebdevToolbox — free, browser-based developer tools with no login required.