Affine Cipher

Encode and decode the affine cipher, E(x) = (a·x + b) mod 26. The multiplier a must be coprime with 26. A classic substitution cipher.

Frequently asked questions

What is the affine cipher?

It is a substitution cipher where each letter's position x is transformed by the formula (a times x plus b) mod 26. The Caesar cipher is the special case where a is 1. Both a and b together form the key.

Why must a be coprime with 26?

Decryption needs the modular inverse of a, which only exists when a shares no factors with 26. Valid choices are 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 and 25. The tool warns you if you pick an invalid a.

How is it decoded?

Decoding applies the inverse formula using the modular inverse of a, which the tool computes for you. As long as a is valid, encoding then decoding returns the original text.