Loading cipher tool...
Please wait a moment

How to Use the Affine Cipher Tool

Work with multiplicative and additive keys while keeping the same page structure and styling as the rest of Cipher Tools.

Quick Overview

The Affine cipher mixes multiplication and addition over the alphabet modulo 26. It is richer than Caesar but still a classical teaching tool rather than real cryptographic protection.

In practice, that means two keys control the mapping: one multiplies the alphabet index and one shifts it. This page validates the multiplier for you, so bad key choices fail early instead of producing text that cannot be reversed. The math is based on modular arithmetic, which is why only some values of a work.

Key a

Must be coprime with 26 so decoding remains possible.

Key b

Shifts the mapped value after multiplication.

Default Example

This page starts with a=5 and b=8.

Step 1

Choose Valid Keys

The multiplier key a must be reversible modulo 26, which is why only certain values are allowed. The additive key b can be any value from 0 to 25. That keeps the page within the rules of a reversible substitution cipher.

Valid a values: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25.
Default b: 8.
Why it matters: invalid a values break decoding.
Step 2

Apply the Formula

The formula is the useful part of Affine because it shows how the cipher extends a plain shift into a small modular arithmetic system. Once that clicks, the key restrictions become much easier to understand, and you can see how it fits into the larger family of classical ciphers.

Encode: E(x) = (ax + b) mod 26
Decode: use the modular inverse of a.
Preserved characters: punctuation and spaces stay in place in this tool.
Step 3

Review the Default Example

Example Input

Affine Cipher

Example Output with a=5, b=8

Ihhwvc Swfrcp

This is a good sanity check because it includes uppercase, lowercase, and spacing. If your output looks wrong on short text, the first thing to verify is the selected value of a.

Step 4

Decode with the Same Keys

To decode, keep the same key pair. If you want a matrix-based next step, continue to Hill Cipher. If you want a simpler shift-based page, go back to Caesar Cipher.

Frequently Asked Questions

Why can't I use every value for a?

Because a must have a modular inverse modulo 26. Without that inverse, decryption is not possible.

Does this tool keep punctuation?

Yes. Only alphabetic letters are transformed.

Is Affine cipher secure?

No. It is still a classical educational cipher rather than strong cryptography.

What does modulo 26 mean here?

It means every calculation wraps around the 26-letter alphabet. Once a value moves past Z, it loops back to A.