Algebra • Modular Cryptography

Algebraic Cipher Generator

The universal modular cryptography calculator for encoding, decoding, and analyzing classical algebraic ciphers over finite integer rings ℤ₂₆ and ℤ₁₂₈. Features real-time coprimality checking, modular multiplicative inverse calculation, character-by-character algebraic breakdowns, and live letter frequency cryptanalysis.

|
Last Updated: August 2026
|
Verified Mathematical Solution
MODULAR ALGEBRA ENGINE Invertible Key • Valid Modulo

Interactive Algebraic Cipher Generator

Cryptographic Presets: Click to load key
Plaintext (x) → Ciphertext E(x)
Algebraic Key Parameters
Inverse a−¹ mod 26 21
26 characters
26 characters
Applied Modular Equation:
E(x) = (5x + 8) mod 26
Decryption Inverse Function:
D(y) = 21(y − 8) mod 26

Sample Letter Transformation Breakdown

Character → Numerical mod 26 mapping
Plain Char Plain Index (x) Formula Evaluation Cipher Index (y) Cipher Char

Letter Frequency Analysis: Plaintext vs. Ciphertext

Monoalphabetic algebraic ciphers preserve the frequency distribution of the underlying language, making them vulnerable to frequency cryptanalysis.

Plaintext
Ciphertext
Direct Answer & Overview
Verified Educational Guide

How an Algebraic Cipher Works

An algebraic cipher encrypts text by mapping each letter to an integer x (where A=0, B=1, ..., Z=25) and evaluating a linear congruence E(x) = (ax + b) mod 26. To decrypt, the recipient uses the modular multiplicative inverse a⁻¹ mod 26 to evaluate D(y) = a⁻¹(y - b) mod 26. For the cipher to be invertible and avoid letter collisions, the multiplier a must be coprime to 26 (meaning gcd(a, 26) = 1).

Primary Mathematical Formula Affine Modular Congruence Model
Standard Equation
ƒ(x)
Q.E.D.
E(x)=(ax+b)(mod26)  ⟺  D(y)=a−1(y−b)(mod26)[gcd⁡(a,26)=1]E(x) = (ax + b) \pmod{26} \quad \iff \quad D(y) = a^{-1}(y - b) \pmod{26} \quad [\gcd(a, 26) = 1]
Evaluated with exact mathematical formulation • Rigorously verified
Exact Formula
Input Parameters
Required
1
Plaintext Message: Input message to encode or ciphertext to decode
2
Multiplier a: Must be coprime to 26 (1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25)
3
Shift b: Additive offset constant between 0 and 25
Expected Outputs
Calculated
Ciphertext Output: Transformed encoded or decoded message
Modular Inverse a⁻¹: Integer satisfying (a · a⁻¹) ≡ 1 mod 26 for exact decryption
Bijection Verification: Confirmation that gcd(a, 26) = 1 prevents letter collisions
Character Mapping Table: Step-by-step arithmetic transformation for each letter
Worked Numerical Example
Instant Verification
Encrypt message "MATH" with keys a = 5, b = 8
→ M(12) → (5·12+8) mod 26 = 16 (Q); A(0) → 8 (I); T(19) → 25 (Z); H(7) → 17 (R)
"QIZR" (Decryption key a⁻¹ = 21, b = 8)

1. What is an Algebraic Cipher?

In classical cryptography and abstract algebra, an algebraic cipher is an encryption scheme that converts letters into numbers, processes those numbers through a mathematical formula operating over a finite ring, and converts the resulting values back into encrypted characters.

Standard English text contains 26 distinct alphabetical letters. By assigning each letter an integer index from 0 to 25:

A = 0
B = 1
C = 2
D = 3
E = 4
F = 5
G = 6
H = 7
I = 8
J = 9
K = 10
L = 11
M = 12
N = 13
O = 14
P = 15
Q = 16
R = 17
S = 18
T = 19
U = 20
V = 21
W = 22
X = 23
Y = 24
Z = 25

2. Modular Rings & The Coprimality Criterion

Algebraic ciphers operate over the finite quotient ring ℤ₂₆. Because clock arithmetic wraps around when numbers exceed 25, division cannot be performed by regular fractions.

Why Multiplier a Must Be Coprime to 26

If gcd(a, 26) ≠ 1, multiple distinct letters will map to the exact same ciphertext output, creating irreversible collisions. There are exactly 12 valid multipliers: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, and 25.

3. Encryption & Decryption Formulas

Encryption
E(x) = (a · x + b) mod 26

Multiply plaintext index x by a, add shift b, and evaluate remainder mod 26.

Decryption
D(y) = a⁻¹(y − b) mod 26

Subtract shift b from ciphertext index y, then multiply by the modular inverse a⁻¹ mod 26.

4. Finding the Modular Multiplicative Inverse (a⁻¹)

The modular inverse a⁻¹ satisfies the congruence (a · a⁻¹) ≡ 1 (mod 26). The 12 valid multipliers and their corresponding modular inverses are:

3⁻¹ = 9
5⁻¹ = 21
7⁻¹ = 15
9⁻¹ = 3
11⁻¹ = 19
15⁻¹ = 7
17⁻¹ = 23
19⁻¹ = 11
21⁻¹ = 5
23⁻¹ = 17
25⁻¹ = 25
1⁻¹ = 1

5. In-Depth Worked Examples

Example: Encrypting and Decrypting "CIPHER"

Keys: a = 7, b = 3. Modular inverse of 7 mod 26 is 15.

C (2) → (7·2 + 3) mod 26 = 17 (R)
I (8) → (7·8 + 3) mod 26 = 59 mod 26 = 7 (H)
P (15) → (7·15 + 3) mod 26 = 108 mod 26 = 4 (E)
H (7) → (7·7 + 3) mod 26 = 52 mod 26 = 0 (A)
E (4) → (7·4 + 3) mod 26 = 31 mod 26 = 5 (F)
R (17) → (7·17 + 3) mod 26 = 122 mod 26 = 18 (S)
Encrypted: "RHEAFS" ✓

6. Classical Cipher Taxonomy

Cipher Name Encryption Rule Decryption Rule Key Space Size
Caesar Cipher (x + 3) mod 26 (y - 3) mod 26 1 fixed key
ROT13 Cipher (x + 13) mod 26 (y + 13) mod 26 1 fixed key (Self-reciprocal)
Multiplicative Cipher (a · x) mod 26 (a⁻¹ · y) mod 26 12 coprime keys
Affine Cipher (a · x + b) mod 26 a⁻¹(y - b) mod 26 12 × 26 = 312 keys

7. Cryptanalysis & Letter Frequency Distribution

Because every occurrence of letter E will always map to the exact same ciphertext character throughout an entire message, monoalphabetic substitution ciphers are entirely vulnerable to frequency cryptanalysis:

Breaking an Affine Cipher with Two Letters

Identify the two most frequent letters in the ciphertext, map them to E (4) and T (19), and solve the 2x2 system of modular linear equations to uncover keys a and b directly.

Frequently Asked Questions

Why must the multiplier a be coprime to 26 in an algebraic affine cipher?
For a cipher to be valid, every distinct plaintext letter must map to a unique ciphertext letter (a bijection or one-to-one function). If gcd(a, 26) > 1, multiple plaintext letters map to the identical ciphertext character (a collision), making unambiguous decryption impossible. Coprimality ensures that a has a unique modular multiplicative inverse a⁻¹ mod 26.
How do you calculate the modular multiplicative inverse a⁻¹ mod 26?
The modular multiplicative inverse a⁻¹ is the integer satisfying (a · a⁻¹) ≡ 1 mod 26. It can be found using the Extended Euclidean Algorithm or Euler's Totient Theorem: a⁻¹ ≡ a^(φ(m)-1) mod m. For m = 26, the 12 coprime multipliers and their inverses are: 1⁻¹=1, 3⁻¹=9, 5⁻¹=21, 7⁻¹=15, 9⁻¹=3, 11⁻¹=19, 15⁻¹=7, 17⁻¹=23, 19⁻¹=11, 21⁻¹=5, 23⁻¹=17, 25⁻¹=25.
What is the difference between a Caesar cipher and an Affine cipher?
A Caesar cipher is a pure shift cipher: E(x) = (x + b) mod 26, where the multiplier a = 1. An Affine cipher combines both multiplication and addition: E(x) = (ax + b) mod 26, providing 312 possible keys instead of just 25.
How does letter frequency analysis break an algebraic cipher?
Because an algebraic cipher is monoalphabetic, each letter consistently transforms to the same output. By calculating the frequency of letters in the ciphertext, the most frequent characters can be mapped to E (index 4) and T (index 19) in English. Setting up two modular equations allows solving for keys a and b in seconds.
What is the difference between Z₂₆ and Z₁₂₈ ASCII modes?
In Z₂₆ mode, the alphabet is restricted to letters A–Z (modulo 26), stripping or preserving spaces and punctuation unchanged. In Z₁₂₈ mode, the modular ring spans all 128 standard ASCII characters (letters, numbers, symbols, spaces), using modulo 128 arithmetic.
Fact-Checked & Verified • Computational Accuracy Standards
Updated September 2026 • Editorial Policy
Authored By
Sanjay Samanta

Lead Developer & Founder of Basic Math Tools. Specializes in browser-native computational algorithms and applied mathematics.

Reviewed & Verified By
Academic Review Board

Mathematics & curriculum specialists. Audited against standard algebraic and arithmetic principles.

Found an error or have an improvement suggestion? Report a calculation issue