ToolPuma Logo

Affine Cipher

Encrypt or decrypt text with the affine substitution cipher.

Note: The affine cipher uses E(x) = (a·x + b) mod 26. The multiplier "a" must be coprime with 26 (choose from 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25) or an error is shown.

What Is a Affine Cipher?

The Affine Cipher tool encrypts and decrypts text with the formula E(x) = (a·x + b) mod 26, a combination of a multiplication and a shift. The multiplier 'a' must be coprime with 26 so that decryption is possible.

How to Use This Affine Cipher

  1. 1
    Enter a and bProvide the multiplier and shift values.
  2. 2
    Enter TextType the plaintext or ciphertext.
  3. 3
    Choose DirectionClick Encrypt or Decrypt to transform the text.

Frequently Asked Questions

Decryption needs a modular inverse of 'a'. That inverse exists only when 'a' and 26 share no common factor, so valid choices are 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, and 25.
Very weak — there are only 12 × 26 = 312 possible keys, so it is easily brute-forced. It is useful for teaching modular arithmetic.