Skip to main content
affineciphercryptographymodular arithmeticwebdevtoolbox

How to Use the Affine Cipher Tool — WebdevToolbox Guide

Encrypt and decrypt text with the Affine cipher, a mathematical substitution cipher using the formula E(x) = (a·x + b) mod 26, with validation that key A is coprime with 26.

WebdevToolbox Team2 min read

The Caesar cipher shifts every letter by the same fixed amount — simple, but also simple to break. The Affine cipher generalizes that idea with actual modular arithmetic: each letter’s position is multiplied by a key before the shift is applied, which is why getting the math right (and choosing a valid key) matters more than it might first appear.

What Is the Affine Cipher Tool?

Enter two keys — A (which must be coprime with 26) and B (a simple shift amount) — along with your text, and the tool applies the formula E(x) = (a·x + b) mod 26 to every letter. It automatically warns you if your chosen A value isn’t valid for decryption, and computes the correct modular inverse behind the scenes when decrypting.

How to Use It

  1. Open the tool at /tools/affine-cipher.
  2. Type your text.
  3. Set key A (must be one of 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25) and key B (0-25).
  4. Click “Encrypt” or “Decrypt”.
  5. Copy the result.

Key Features

  • Automatic key validation — warns immediately if A isn’t coprime with 26, which would make decryption impossible.
  • Correct modular inverse calculation for decryption, computed automatically behind the scenes.
  • Generalizes the Caesar cipher — setting A=1 reproduces standard Caesar-cipher behavior exactly.
  • Matches the well-known A=5, B=8 reference example exactly.

When to Use This Tool

  • Learning how modular arithmetic underlies classical substitution ciphers.
  • Understanding why cipher key choices matter mathematically, not just as arbitrary numbers.
  • Solving or building cryptography puzzles that use the Affine cipher.

Try It Now

Open Affine Cipher directly, or press ⌘K and type the tool name from anywhere on the site.


Part of the Security & Crypto collection on WebdevToolbox — free, browser-based developer tools with no login required.

Tagged with

affineciphercryptographymodular arithmeticwebdevtoolbox

Related posts