LinguaholicTools

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.

Encoded
Rclla Oaplx

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

  1. Choose Encode or Decode.
  2. Set the keys a and b.
  3. 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.