# Affine Cipher > Encode and decode the affine cipher with keys a and b, see the arithmetic for every letter, or crack a message by trying all 312 keys. - Page: https://linguaholic.com/tools/affine-cipher/ - Type: free online tool (Converters & translators), no sign-up, runs in the browser - Publisher: Linguaholic (https://linguaholic.com/), made by Marcel Iseli - Last updated: October 3, 2026 - Open it pre-filled: https://linguaholic.com/tools/affine-cipher/?text=IHHWVC+SWFRCP&mode=decode&a=5&b=8 - `text`: text to encode or decode (for example `IHHWVC SWFRCP`) - `mode`: direction: encode (default) or decode (for example `decode`) - `a`: multiplicative key, 1-25 and coprime with 26 (1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25); other values are ignored; default 5 (for example `5`) - `b`: additive key, 0-25 (clamped); default 8 (for example `8`) - `open`: open a section: crack (all 312 keys ranked), steps (cipher alphabet and the arithmetic per letter), frequency (letter counts) or identify (which cipher is this?) (for example `crack`) ## What is the affine cipher? The **affine cipher** turns each letter into a number (A = 0 … Z = 25), multiplies it by a key **a**, adds a second key **b**, and turns the result back into a letter, wrapping around after 25. It is a substitution cipher like the Caesar cipher, with one extra step: the multiplication scrambles the alphabet instead of only sliding it along. The [Caesar cipher](https://linguaholic.com/tools/caesar-cipher/) is the affine cipher with a = 1, and [Atbash](https://linguaholic.com/tools/atbash-cipher/) is the affine cipher with a = 25 and b = 25. It is mostly met in math and computer science classes, because it is a friendly way to practice modular arithmetic: encoding needs multiplication mod 26, and decoding needs a modular inverse. ## How to use the affine cipher decoder and encoder 1. Choose **Encode** or **Decode**. 2. Set **a** with the − and + buttons; they step through only the twelve values that work (1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25). Set **b** anywhere from 0 to 25. 3. Type or paste the text. Case, spaces, digits and punctuation are kept. 4. Copy the result, or press **Decode this** to check it. **No key?** Open **Crack it: I don’t know the key**: the tool tries all 312 key pairs and ranks them by how much the result reads like English, and **Use a = …, b = …** applies the winner. **Step by step** shows the full cipher alphabet for your keys and the arithmetic for each letter. A link such as `?text=IHHWVC&mode=decode&a=5&b=8` opens the tool filled in. ## Frequently asked questions **What is the affine cipher?** A substitution cipher that numbers the letters from A = 0 to Z = 25, multiplies each by a key a, adds a key b, and takes the result mod 26. The Caesar cipher is the special case a = 1. **What is the affine cipher formula?** Encoding is E(x) = (ax + b) mod 26 and decoding is D(y) = a⁻¹(y - b) mod 26, where a⁻¹ is the modular inverse of a. **How do I decrypt an affine cipher?** Find the inverse of a (for a = 5 it is 21), subtract b from each cipher letter's number, multiply by the inverse and take the remainder mod 26. In the tool, choose Decode and enter a and b. **Which values of a can I use?** Only numbers that share no factor with 26: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 and 25. Any other a sends two letters to the same cipher letter, so the message could not be decoded. **How many keys does the affine cipher have?** 12 values of a times 26 values of b gives 312 key pairs, one of which (a = 1, b = 0) leaves the text unchanged. **How do you crack an affine cipher without the key?** Try all 312 keys and keep the one that reads as English, which the tool's Crack it section does instantly. By hand, guess two letters (the most common cipher letters are likely E and T) and solve two equations for a and b. **What is a modular inverse?** The number that undoes a multiplication in clock arithmetic. The inverse of 5 mod 26 is 21, because 5 × 21 = 105, which is 4 × 26 + 1. **Is Atbash an affine cipher?** Yes. Atbash is the affine cipher with a = 25 and b = 25, since 25x + 25 mod 26 equals 25 - x. **Is my text private?** Yes. The tool runs entirely in your browser, and nothing you type is uploaded or stored. ## Data sources The code breaker's English letter frequencies and word checks come from Linguaholic’s English dictionary, built from the open ENABLE and SCOWL word lists. Licenses and notices: https://linguaholic.com/tools/data/dict/v1/NOTICE.txt ## Related tools - [Caesar Cipher](https://linguaholic.com/tools/caesar-cipher/): Encode and decode the Caesar shift cipher with any shift from 1 to 25, or crack a message without the key: every shift is tried and ranked for you. - [Atbash Cipher](https://linguaholic.com/tools/atbash-cipher/): Encode and decode the Atbash cipher, which swaps each letter with its mirror (A↔Z, B↔Y), with the alphabet chart, step-by-step working and examples. - [Substitution Cipher](https://linguaholic.com/tools/substitution-cipher/): Encode and decode with any cipher alphabet or keyword, or paste a cryptogram and let the solver crack it; then fix any letter yourself. - [Vigenère Cipher](https://linguaholic.com/tools/vigenere-cipher/): Encode and decode the Vigenère cipher with a keyword, or crack a message without the key: the tool finds the key length and the keyword for you. - [ROT13](https://linguaholic.com/tools/rot13/): Decode and encode ROT13 instantly (the same step does both), switch to ROT5, ROT18 or ROT47, or try every rotation when it is not ROT13. - [Morse Code Translator](https://linguaholic.com/tools/morse-code-translator/): Translate text to Morse code and decode it back, hear it as adjustable-speed sound with a visual flasher, and read the full Morse alphabet, number, and punctuation chart.