🔒 Classical Cryptography

Affine Cipher Encoder & Decoder

Instantly encrypt or decrypt text using the Affine Cipher algorithm. Enter your keys, paste your text, and get results in real time — no installation required.

12
Valid 'a' Key Values
26
Alphabet Size (mod)
312
Possible Key Pairs
100%
Browser-Based
Live Tool

Affine Cipher Calculator

Real-time encoding and decoding with live validation, step-by-step breakdown, and character mapping.

Input & Configuration
Valid values for key a:
Output & Analysis
Result
Your encoded/decoded text will appear here...
Input: 0 chars
Output: 0 chars
Alpha: 0
Mode: Encode
Formula Used
E(x) = (5x + 8) mod 26
where x = letter position (A=0 … Z=25)
Features

Why Use Our Affine Cipher Tool?

Built for students, cryptography enthusiasts, security researchers, and educators.

Real-Time Processing

Results update instantly as you type — no button clicks needed for live preview mode. Instant affine cipher computation in your browser.

Input Validation

Intelligent real-time validation ensures your key 'a' is always coprime with 26. Clear error messages guide you to correct inputs instantly.

Alphabet Mapping

Visualise the full A–Z substitution table for your chosen key pair. Understand exactly how each character is transformed by the cipher.

Encode & Decode

Switch seamlessly between encryption and decryption. The decoder automatically computes the modular inverse of key 'a' for you.

Privacy First

All processing happens entirely in your browser. No text is ever sent to a server — your data stays 100% private and local.

Formula Display

See the exact mathematical formula being applied (E(x) or D(x)) updated dynamically with your chosen key values for full transparency.

Algorithm

How the Affine Cipher Works

A step-by-step explanation of the Affine Cipher encryption and decryption process.

Choose Your Keys

Select key 'a' (must be coprime with 26) and key 'b' (any integer 0–25). Together they form your cipher key pair.

Convert Letters

Each letter is converted to a number: A=0, B=1, … Z=25. Non-alphabetic characters pass through unchanged.

Apply the Formula

Encryption: E(x) = (ax + b) mod 26. Each letter number is plugged into this linear congruential formula.

Convert Back

The resulting numbers are converted back to letters and assembled into the ciphertext or plaintext output.

Mathematical Formulas

Encryption: E(x) = (a · x + b) mod 26
Decryption: D(x) = a⁻¹ · (x − b) mod 26
Modular Inverse condition: a · a⁻¹ ≡ 1 (mod 26)

Example: With a=5, b=8 — encoding 'A' (x=0): E(0) = (5·0 + 8) mod 26 = 8 → 'I'. Decoding 'I' (x=8): a⁻¹ of 5 mod 26 = 21. D(8) = 21·(8−8) mod 26 = 0 → 'A'. ✓

About

Understanding the Affine Cipher: Algorithm, Use Cases & More

The Affine Cipher is one of the oldest and most elegant forms of classical cryptography — a monoalphabetic substitution cipher built on a straightforward linear algebraic formula. Unlike the simple Caesar cipher, which shifts every letter by a fixed number, the Affine Cipher applies a two-key mathematical transformation: E(x) = (ax + b) mod 26. Here, 'a' acts as a multiplicative key while 'b' functions as an additive shift, giving the cipher its name from the mathematical concept of an affine function.

The Affine Cipher algorithm operates over the 26-letter alphabet by mapping each letter to a numerical equivalent (A=0, B=1 … Z=25), applying the formula, then converting the result back to a letter. For decryption, the process reverses using the modular multiplicative inverse of 'a': D(x) = a⁻¹(x − b) mod 26. A key constraint is that 'a' must be coprime with 26 — meaning gcd(a, 26) = 1 — which limits valid choices to just 12 values: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, and 25. Combined with 26 choices for 'b', this yields 312 unique key pairs.

Use cases for the Affine Cipher today are primarily educational. It is commonly studied in computer science, mathematics, and information security curricula to demonstrate the principles of substitution ciphers, modular arithmetic, and cryptanalysis via frequency analysis. Security researchers use it as a baseline to explain how symmetric key encryption evolved and why modern algorithms like AES are necessary. Puzzle designers and escape room creators also rely on Affine Ciphers for crafting engaging cryptographic challenges. Our free online Affine Cipher encoder decoder calculator makes it effortless to explore all 312 key combinations with real-time validation, instant results, and a full alphabet mapping visualization — ideal for learners and professionals alike.

FAQ

Frequently Asked Questions

Everything you need to know about the Affine Cipher.

The Affine Cipher is a monoalphabetic substitution cipher where each letter is encrypted using the formula E(x) = (ax + b) mod 26. It is a generalisation of the Caesar cipher and the Atbash cipher, combining multiplicative and additive transformations over the 26-letter alphabet.
For decryption to work, we need the modular multiplicative inverse of 'a' modulo 26. This inverse exists only when gcd(a, 26) = 1, i.e. when 'a' and 26 share no common factors. If this condition is not met, multiple letters would map to the same ciphertext letter, making decryption impossible.
The Affine Cipher has 12 valid values for key 'a' (coprime with 26) and 26 values for key 'b' (0–25), giving 12 × 26 = 312 unique key pairs. However, when a=1 and b=0, the cipher performs no transformation, so effectively 311 meaningful key combinations exist.
The Affine Cipher can be broken using frequency analysis — a classical cryptanalysis technique. Since it is a monoalphabetic cipher, each letter maps to exactly one ciphertext letter. By analysing letter frequencies in the ciphertext and matching them to known English frequency patterns, an attacker can deduce the key pair. With only 312 possible combinations, brute-force is also trivially easy.
The Caesar Cipher is a special case of the Affine Cipher where a=1. In this case E(x) = (1·x + b) mod 26 = (x + b) mod 26, which is simply a shift cipher. The Affine Cipher is more general because it also applies multiplication (key 'a'), making it slightly stronger, though still insecure by modern standards.
Yes, our Affine Cipher encoder decoder is fully responsive and mobile-friendly. It works seamlessly on smartphones, tablets, laptops, and desktops. All processing runs entirely in your browser with no app download required.
The modular multiplicative inverse of 'a' mod 26 is the number a⁻¹ such that (a × a⁻¹) ≡ 1 (mod 26). For example, the inverse of 5 mod 26 is 21, since 5×21 = 105 = 4×26 + 1. Our tool computes this automatically using the Extended Euclidean Algorithm, so you never need to calculate it manually.
Explore More

Discover More Powerful Crypto & AI Tools

Access our complete suite of free online cryptography tools, encryption utilities, and AI-powered productivity tools — all in one place.

Disclaimer: The Affine Cipher is a classical cipher intended for educational, research, and recreational use only. It is not suitable for securing sensitive data in modern applications. All trademarks, brand names, and third-party tool names referenced on this page are the property of their respective owners. SEOWebChecker is not affiliated with any third-party trademark holders. All cipher computations run locally in your browser; no data is transmitted to or stored on any server.