Affine Cipher

Encrypt and decrypt text using the Affine cipher — a substitution cipher using modular arithmetic with keys a and b.

What Does This Tool Do?

The Affine cipher encrypts each letter using E(x) = (ax + b) mod 26, where a must be coprime with 26. It is a generalisation of the Caesar cipher (a=1) and Atbash cipher (a=25, b=25).

Key Features

🔢
Two Keys
Keys a (multiplicative) and b (shift).
📐
Modular Arithmetic
E(x) = (ax+b) mod 26 formula shown.
🔄
Both Directions
Encrypt and decrypt.
Valid Key Check
Warns if a is not coprime with 26.

How to Use

  1. Enter your message.
  2. Select key a (must be coprime with 26) and enter key b (0–25).
  3. Click Encrypt or Decrypt.

Frequently Asked Questions

Why must key a be coprime with 26?
For decryption to work, the modular inverse of a must exist. A modular inverse of a mod 26 exists only when gcd(a, 26) = 1 — i.e. a is coprime with 26.
What is the formula?
Encryption: E(x) = (a×x + b) mod 26. Decryption: D(y) = a⁻¹×(y − b) mod 26, where a⁻¹ is the modular inverse of a.
What are the special cases?
a=1 gives a Caesar cipher (shift by b). a=25, b=25 gives an Atbash cipher. a=1, b=0 gives no encryption at all.

Complete Guide to Affine Cipher

When To Use This Tool

Use Affine Cipher whenever you need fast, accurate output without installing software. This tool is designed for speed, clarity, and repeatable results for day-to-day work.

Best Practices for Accurate Results

  • Double-check the format of your input before running the tool.
  • Test with a small sample first, then process larger data.
  • Use Related Tools to verify, convert, or transform the output.

Why Users Prefer AdeDX

AdeDX tools are browser-based, free to use, and built to work across desktop and mobile devices. Most processing happens directly in your browser for fast performance and improved privacy.