Encrypt and decrypt the ax+b affine cipher with live modular-inverse check, browser-only
- Runs locally
- Category Encoding & Crypto
- Best for Checking small payloads, tokens, hashes, and encoded values quickly.
E(x) = (a·x + b) mod 26Modular inverse a⁻¹ mod 26 = 21.Transformed text appears here.What this tool does
Free online affine cipher tool that encrypts and decrypts the classic ax+b substitution cipher right in your browser. The affine cipher maps each letter x to a times x plus b, all taken modulo 26, so it generalises the Caesar shift by adding a multiply step before the add. Enter your two keys, a and b, choose encrypt or decrypt, and every letter transforms live while case is preserved and digits, spaces, punctuation, accented letters and CJK text pass through untouched, because the cipher is defined only on A to Z and a to z. The key a must be coprime with 26, meaning one of 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 or 25; any other a has no modular inverse and the tool flags it instead of producing a cipher that cannot be decoded. Decryption multiplies by the modular inverse of a, which is shown on screen so you can follow the maths. Everything is 100% client-side with a one-click copy button and a shareable link that reopens the same text and the same a and b. No upload, no server round-trip.
Tool details
- Input
- Files + Text + Numbers
- The page exposes text boxes, numeric controls, file pickers, or structured inputs depending on the tool.
- Output
- Live result + Copy
- The result area focuses on usable output, with copy, download, or preview actions when supported.
- Privacy
- Browser-side processing
- The main tool logic does not call an external API, so inputs normally stay in the current tab.
- Save / share
- Shareable URL state
- Key settings are encoded in the URL so another person can reopen the same setup.
- Performance budget
- Initial JS <= 9 KB
- No WASM budget is declared, keeping the tool quick to open on mobile.
- Best fit
- Encoding & Crypto · Student
- Category and role tags drive related tools, internal links, and quick fit checks.
How to use
-
1. Input
Paste or drop your content into the tool panel.
-
2. Process
Click the button. All processing is local in your browser.
-
3. Copy / Download
Copy the result or download to disk in one click.
How Affine Cipher Encoder & Decoder fits into your work
Use it for quick browser-side encoding, decoding, hashing, token checks, and share-safe transformations.
Encoding jobs
- Checking small payloads, tokens, hashes, and encoded values quickly.
- Preparing values for APIs, URLs, docs, or support tickets.
- Avoiding account-based tools when the input might be sensitive.
Encoding checks
- Do not paste live secrets unless you are comfortable with local browser handling.
- Confirm whether the operation is reversible before sharing the result.
- For hashes, compare the exact algorithm and casing expected by the receiver.
Good next steps
These links move the current task into a more complete workflow.
- 1 Caesar Cipher Encoder & Decoder Encrypt, decrypt and brute-force a Caesar shift cipher — all 25 shifts at once, ROT13 shortcut, browser-only Open
- 2 Vigenère Cipher Encoder / Decoder Encrypt and decrypt with a keyword, polyalphabetic shift, case kept, non-letters passed through, browser-only Open
- 3 Atbash Cipher Mirror the alphabet, A↔Z B↔Y, no key, self-reciprocal so the same button encodes and decodes, browser-only Open
Real-world use cases
Solve an affine cipher in a CTF crypto challenge
A challenge hands you ciphertext and the hint that the key is "ax+b". Set a and b, switch to decrypt, and the flag inside CTF{...} resolves instantly. If only the ciphertext is given, the two unknowns a and b mean there are 12 valid choices for a times 26 for b, so paste a known crib like the flag prefix, try a few coprime a values, and read the line where the braces frame plain text.
Teach modular inverses in a number-theory class
The affine cipher is the cleanest classroom example of why a number needs a multiplicative inverse mod 26. Type a value of a that shares a factor with 26, such as 13, and the tool refuses with a clear error; switch to a coprime a like 5 and it shows the inverse 21, then decrypts correctly. Students see in real time why gcd(a, 26) = 1 is not optional.
Show that Caesar is a special case of affine
Set a to 1 and the formula 1 times x plus b collapses to plain addition, which is exactly the Caesar shift by b. Encode a sentence at a = 1, b = 3 here and at shift 3 in the Caesar tool and the outputs match character for character. It makes the family relationship between shift, affine and substitution ciphers concrete instead of abstract.
Build a puzzle for an escape room or a treasure hunt
You want a clue that looks scrambled but decodes with a small printed key card. Pick a = 7, b = 11, encrypt the riddle, and print the cipher plus the line "key a equals 7, b equals 11" on the card. Players who find the card paste the text, enter the two numbers, hit decrypt and get the next location. The shareable link reopens the same puzzle.
Common pitfalls
Choosing an a that is not coprime with 26. If gcd(a, 26) is greater than 1, such as a = 2, 13 or 26, no modular inverse exists, two different letters can map to the same cipher letter, and decryption is impossible. The valid a values are exactly 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 and 25; the tool blocks every other a with an error.
Mixing up the encrypt and decrypt formulas. Encryption is a times x plus b, but decryption is not a times y minus b. You must multiply by the modular inverse of a, giving the inverse of a times the quantity y minus b. Use the Decrypt button rather than swapping a and b by hand, or the result stays scrambled.
Expecting digits and punctuation to be enciphered. The affine cipher is defined only on A to Z. A string like "Day 9!" leaves the 9, the space and the exclamation mark untouched and only transforms the letters. If a "decoded" message still has its original numbers, that is correct behaviour, not a bug.
Privacy
Every step runs in plain JavaScript inside your browser tab. The affine formula, the modular inverse and the encrypt or decrypt pass all happen on the page, and the text you type never leaves it, with no logging of what you encode. State this plainly though: the affine cipher is not real encryption. With only 12 valid choices for a and 26 for b there are 312 keys in total, breakable in a blink, so never use it to protect a password or a private message. The shareable URL encodes your text, a and b in the query string, so a link pasted into chat lands those characters in the recipient server access log. Use it for puzzles and lessons, not secrets.
FAQ
Tool combos
Folks in your role tend to reach for these alongside this tool.
- 24-Point Solver & Game 24-point solver and game — enter 4 numbers and get every solution instantly, or play random hands against the clock.
- Chinese Acupoint Locator 200+ meridian acupoints / WHO 2008 standard locations / with contraindications, manipulation, and combinations.
- Add Days to Date Calculator Add or subtract days, weeks, months, and years from any date — plus a business-day mode that skips weekends. Runs entirely in your browser.
- Age Calculator Calculate your exact age — years, months, days, hours. Compare two dates or count to a future date.