Affine Cipher Encoder & Decoder
Encode and decode the affine cipher, a substitution cipher that applies the formula (a×x + b) mod 26 to each letter, with automatic decoding.
What is the affine cipher?
The affine cipher is a substitution cipher built on a little modular arithmetic. Each letter’s position x is transformed with the formula (a × x + b) mod 26, combining a multiplicative key a and an additive key b.
How to use it
- Choose Encode or Decode.
- Set the keys a and b.
- Type your text and copy the result.
How the affine cipher works
The additive key b acts like a Caesar shift, while the multiplicative key a spreads the letters out. For decoding to be possible, a must be coprime with 26 — valid values are 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, and 25 — because the tool needs the modular inverse of a to reverse the formula, which it computes for you.
Where it is used
The affine cipher is a favourite in cryptography courses for showing how modular arithmetic underpins classical ciphers.
More codes and ciphers
Explore the rest of the family: the Caesar Cipher, Atbash, Vigenère, and A1Z26. For other encodings, try the Morse Code Translator and the Binary Translator.
Free and private
This affine cipher tool runs entirely in your browser — free, with no sign-up, and nothing you type is uploaded or stored.
Frequently asked questions
- What is the affine cipher?
- The affine cipher is a substitution cipher where each letter's position x is transformed with the formula (a×x + b) mod 26. It combines a multiplicative key (a) and an additive key (b).
- Why must 'a' be coprime with 26?
- Decoding requires the modular inverse of a, which only exists when a shares no factors with 26. Valid values of a are 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, and 25; other values cannot be decoded uniquely.
- How do I decode an affine cipher?
- Enter the same a and b values used to encode and choose Decode. The tool computes the modular inverse of a automatically to reverse the formula.
- Is it free and private?
- Yes — it runs entirely in your browser with no sign-up, and nothing you type is uploaded.
More free tools
- Morse Code TranslatorTranslate 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.
- Roman Numeral ConverterConvert numbers to Roman numerals and back, turn any date into Roman numerals for tattoos, and read the full chart from 1 to 1000.
- Binary TranslatorTranslate text to binary code and back, convert between decimal and binary numbers, and read the full binary alphabet chart.
- NATO Phonetic AlphabetSpell any word or name in the NATO phonetic alphabet (Alpha, Bravo, Charlie…), hear it read aloud, and browse the full chart with pronunciations, numbers, and the police alphabet.
- Braille TranslatorTranslate English text to Grade 1 Braille and Braille back to text, and read the full Braille alphabet and number chart.
- Hex to TextConvert hexadecimal to readable text and text to hex instantly, both directions, with a full hex ASCII reference chart. Private and works offline.