Affine Cipher Encoder/Decoder
Interactive Affine Cipher Calculator for encoding and decoding text using the Affine cipher, a popular cryptography technique.
Full original guide (expanded)
Affine Cipher Encoder/Decoder
Encrypt or decrypt messages with an affine cipher by setting multiplier and shift keys. Review modular steps per character to validate the mapping.
Affine Cipher Tool
Must be coprime with m (e.g. for m = 26, valid a: 1,3,5,7,9,11,15,17,19,21,23,25).
Any integer. We automatically reduce a and b modulo m.
Modular inverse & key details
Per-character mapping steps
How the Affine Cipher Works
The Affine Cipher is a classical substitution cipher. Each letter is first mapped to a number, transformed with a linear function modulo the alphabet size, and then mapped back to a letter.
Letter-to-number mapping
For the standard English alphabet:
Encryption formula
Let:
- m = size of the alphabet (26 for A–Z)
- a, b = integer keys
- x = numeric value of a plaintext letter
The result E(x) is then converted back to a letter.
Decryption formula
To decrypt, you must compute the modular inverse of a modulo m, denoted a⁻¹, such that:
Then, for each ciphertext letter with numeric value y:
Valid values of a
The cipher is only invertible if a and m are coprime (their greatest common divisor is 1). For the 26-letter alphabet, the valid values of a are:
If you choose an invalid a, this tool will warn you and refuse to decrypt, because no modular inverse exists.
Example: Encrypting “AFFINE CIPHER”
Using keys a = 5, b = 8, m = 26:
- Map letters to numbers: A=0, F=5, I=8, N=13, E=4, C=2, P=15, H=7, R=17.
- Apply E(x) = (5·x + 8) mod 26 to each letter.
- Map the results back to letters.
The tool above shows each step, including the numeric mapping and modular arithmetic, so you can follow the process line by line.
Common Questions
Can I use a custom alphabet?
Yes. Choose “Custom alphabet” and enter any sequence of unique characters. The length of this string becomes the modulus m. This is useful for:
- Including digits (0–9) or punctuation
- Working with non-English alphabets
- Designing puzzle-specific symbol sets
How does this tool handle spaces and punctuation?
By default, spaces, punctuation, and digits are preserved unchanged (they are not encrypted). If you want them to be part of the cipher, include them in a custom alphabet and uncheck “Keep spaces, punctuation, digits”.
Is the Affine Cipher secure?
No. The Affine Cipher is easily broken with frequency analysis or by trying all possible key pairs. It is useful for learning and puzzles, but not for protecting sensitive information.
FAQ
How do I choose good keys a and b?
First pick a value of a that is coprime with the alphabet size m. For A–Z, use one of the 12 valid values listed above. Then choose any integer for b. This tool automatically reduces both a and b modulo m, so you do not need to worry about negative or large values.
What happens if I use an invalid a?
If gcd(a, m) ≠ 1, the mapping is not one-to-one: multiple plaintext letters map to the same ciphertext letter. In that case, decryption is impossible. The calculator detects this and shows an error instead of producing misleading output.
Can I recover the keys from a known plaintext and ciphertext?
In theory, yes: two distinct plaintext–ciphertext letter pairs are enough to solve for a and b. This is one reason the Affine Cipher is weak. This tool focuses on encoding/decoding, but you can use the formulas to solve for a and b manually:
y₂ ≡ a·x₂ + b (mod m)
Subtract the equations to solve for a, then back-substitute to find b.
About the author
Ugo Candido builds financial tools and educational resources to help readers make better money decisions. He focuses on practical, transparent models that reflect how lenders calculate payments and total cost of ownership.
Contact: info@calcdomain.com
Editorial policy
CalcDomain content is created for educational purposes and is reviewed for clarity, accuracy, and transparency. We do not accept paid placements that influence calculator outputs. Inputs and assumptions are shown directly in the interface so you can verify how results are produced.
Methodology
Results use standard formulas and the values you provide. Figures are estimates and may differ from lender quotes. For decisions that require professional guidance, consult a licensed advisor.
Sources
Inputs used by this calculator
- Mode Encrypt
- Decrypt
- Alphabet A–Z (26 letters) Custom alphabet… Custom alphabet Characters must be unique. Alphabet length defines modulus m. Key a (multiplicative) Must be coprime with m (e.g. for m = 26, valid a: 1,3,5,7,9,11,15,17,19,21,23,25). Key b (additive) Any integer. We automatically reduce a and b modulo m. Options Preserve letter case
- Keep spaces, punctuation, digits
- Group ciphertext in blocks of 5
- Show per-character steps
Consistency checks
Checks: non-negative values, plausible ranges, coherent outputs.
Operational notes
Fill in realistic values and keep units and timeframes consistent.
Key entities: Affine, Cipher, Mode Encrypt, Decrypt, Alphabet A–Z (26 letters) Custom alphabet… Custom alphabet Characters must be unique. Alphabet length defines modulus m. Key a (multiplicative) Must be coprime with m (e.g. for m = 26, valid a: 1,3,5,7,9,11,15,17,19,21,23,25). Key b (additive) Any integer. We automatically reduce a and b modulo m. Options Preserve letter case, Keep spaces, punctuation, digits, Group ciphertext in blocks of 5, Show per-character steps.
Inputs used by this calculator
- Mode Encrypt
- Decrypt
- Alphabet A–Z (26 letters) Custom alphabet… Custom alphabet Characters must be unique. Alphabet length defines modulus m. Key a (multiplicative) Must be coprime with m (e.g. for m = 26, valid a: 1,3,5,7,9,11,15,17,19,21,23,25). Key b (additive) Any integer. We automatically reduce a and b modulo m. Options Preserve letter case
- Keep spaces, punctuation, digits
- Group ciphertext in blocks of 5
- Show per-character steps
Consistency checks
Checks: non-negative values, plausible ranges, coherent outputs.
Formula (LaTeX) + variables + units
','
E(x) = (ax + b) \mod m
D(x) = a^{-1}(x - b) \mod m
E(7) = (5 \times 7 + 8) \mod 26
E(7) = (35 + 8) \mod 26
E(7) = 43 \mod 26 = 17
Encoding: $ E(x) = (ax + b) \mod m $ Decoding: $ D(x) = a^{-1}(x - b) \mod m $
$ E(7) = (5 \times 7 + 8) \mod 26 $ $ E(7) = (35 + 8) \mod 26 $ $ E(7) = 43 \mod 26 = 17 $
- No variables provided in audit spec.
- Home — calcdomain.com · Accessed 2026-01-19
https://calcdomain.com/ - Lifestyle & Everyday Calculators — calcdomain.com · Accessed 2026-01-19
https://calcdomain.com/lifestyle-everyday - Hobbies — calcdomain.com · Accessed 2026-01-19
https://calcdomain.com/hobbies
Last code update: 2026-01-19
- Initial audit spec draft generated from HTML extraction (review required).
- Verify formulas match the calculator engine and convert any text-only formulas to LaTeX.
- Confirm sources are authoritative and relevant to the calculator methodology.
Affine Cipher Encoder/Decoder
Encrypt or decrypt messages with an affine cipher by setting multiplier and shift keys. Review modular steps per character to validate the mapping.
Affine Cipher Tool
Must be coprime with m (e.g. for m = 26, valid a: 1,3,5,7,9,11,15,17,19,21,23,25).
Any integer. We automatically reduce a and b modulo m.
Modular inverse & key details
Per-character mapping steps
How the Affine Cipher Works
The Affine Cipher is a classical substitution cipher. Each letter is first mapped to a number, transformed with a linear function modulo the alphabet size, and then mapped back to a letter.
Letter-to-number mapping
For the standard English alphabet:
Encryption formula
Let:
- m = size of the alphabet (26 for A–Z)
- a, b = integer keys
- x = numeric value of a plaintext letter
The result E(x) is then converted back to a letter.
Decryption formula
To decrypt, you must compute the modular inverse of a modulo m, denoted a⁻¹, such that:
Then, for each ciphertext letter with numeric value y:
Valid values of a
The cipher is only invertible if a and m are coprime (their greatest common divisor is 1). For the 26-letter alphabet, the valid values of a are:
If you choose an invalid a, this tool will warn you and refuse to decrypt, because no modular inverse exists.
Example: Encrypting “AFFINE CIPHER”
Using keys a = 5, b = 8, m = 26:
- Map letters to numbers: A=0, F=5, I=8, N=13, E=4, C=2, P=15, H=7, R=17.
- Apply E(x) = (5·x + 8) mod 26 to each letter.
- Map the results back to letters.
The tool above shows each step, including the numeric mapping and modular arithmetic, so you can follow the process line by line.
Common Questions
Can I use a custom alphabet?
Yes. Choose “Custom alphabet” and enter any sequence of unique characters. The length of this string becomes the modulus m. This is useful for:
- Including digits (0–9) or punctuation
- Working with non-English alphabets
- Designing puzzle-specific symbol sets
How does this tool handle spaces and punctuation?
By default, spaces, punctuation, and digits are preserved unchanged (they are not encrypted). If you want them to be part of the cipher, include them in a custom alphabet and uncheck “Keep spaces, punctuation, digits”.
Is the Affine Cipher secure?
No. The Affine Cipher is easily broken with frequency analysis or by trying all possible key pairs. It is useful for learning and puzzles, but not for protecting sensitive information.
FAQ
How do I choose good keys a and b?
First pick a value of a that is coprime with the alphabet size m. For A–Z, use one of the 12 valid values listed above. Then choose any integer for b. This tool automatically reduces both a and b modulo m, so you do not need to worry about negative or large values.
What happens if I use an invalid a?
If gcd(a, m) ≠ 1, the mapping is not one-to-one: multiple plaintext letters map to the same ciphertext letter. In that case, decryption is impossible. The calculator detects this and shows an error instead of producing misleading output.
Can I recover the keys from a known plaintext and ciphertext?
In theory, yes: two distinct plaintext–ciphertext letter pairs are enough to solve for a and b. This is one reason the Affine Cipher is weak. This tool focuses on encoding/decoding, but you can use the formulas to solve for a and b manually:
y₂ ≡ a·x₂ + b (mod m)
Subtract the equations to solve for a, then back-substitute to find b.
About the author
Ugo Candido builds financial tools and educational resources to help readers make better money decisions. He focuses on practical, transparent models that reflect how lenders calculate payments and total cost of ownership.
Contact: info@calcdomain.com
Editorial policy
CalcDomain content is created for educational purposes and is reviewed for clarity, accuracy, and transparency. We do not accept paid placements that influence calculator outputs. Inputs and assumptions are shown directly in the interface so you can verify how results are produced.
Methodology
Results use standard formulas and the values you provide. Figures are estimates and may differ from lender quotes. For decisions that require professional guidance, consult a licensed advisor.
Sources
Inputs used by this calculator
- Mode Encrypt
- Decrypt
- Alphabet A–Z (26 letters) Custom alphabet… Custom alphabet Characters must be unique. Alphabet length defines modulus m. Key a (multiplicative) Must be coprime with m (e.g. for m = 26, valid a: 1,3,5,7,9,11,15,17,19,21,23,25). Key b (additive) Any integer. We automatically reduce a and b modulo m. Options Preserve letter case
- Keep spaces, punctuation, digits
- Group ciphertext in blocks of 5
- Show per-character steps
Consistency checks
Checks: non-negative values, plausible ranges, coherent outputs.
Operational notes
Fill in realistic values and keep units and timeframes consistent.
Key entities: Affine, Cipher, Mode Encrypt, Decrypt, Alphabet A–Z (26 letters) Custom alphabet… Custom alphabet Characters must be unique. Alphabet length defines modulus m. Key a (multiplicative) Must be coprime with m (e.g. for m = 26, valid a: 1,3,5,7,9,11,15,17,19,21,23,25). Key b (additive) Any integer. We automatically reduce a and b modulo m. Options Preserve letter case, Keep spaces, punctuation, digits, Group ciphertext in blocks of 5, Show per-character steps.
Inputs used by this calculator
- Mode Encrypt
- Decrypt
- Alphabet A–Z (26 letters) Custom alphabet… Custom alphabet Characters must be unique. Alphabet length defines modulus m. Key a (multiplicative) Must be coprime with m (e.g. for m = 26, valid a: 1,3,5,7,9,11,15,17,19,21,23,25). Key b (additive) Any integer. We automatically reduce a and b modulo m. Options Preserve letter case
- Keep spaces, punctuation, digits
- Group ciphertext in blocks of 5
- Show per-character steps
Consistency checks
Checks: non-negative values, plausible ranges, coherent outputs.
Formula (LaTeX) + variables + units
','
E(x) = (ax + b) \mod m
D(x) = a^{-1}(x - b) \mod m
E(7) = (5 \times 7 + 8) \mod 26
E(7) = (35 + 8) \mod 26
E(7) = 43 \mod 26 = 17
Encoding: $ E(x) = (ax + b) \mod m $ Decoding: $ D(x) = a^{-1}(x - b) \mod m $
$ E(7) = (5 \times 7 + 8) \mod 26 $ $ E(7) = (35 + 8) \mod 26 $ $ E(7) = 43 \mod 26 = 17 $
- No variables provided in audit spec.
- Home — calcdomain.com · Accessed 2026-01-19
https://calcdomain.com/ - Lifestyle & Everyday Calculators — calcdomain.com · Accessed 2026-01-19
https://calcdomain.com/lifestyle-everyday - Hobbies — calcdomain.com · Accessed 2026-01-19
https://calcdomain.com/hobbies
Last code update: 2026-01-19
- Initial audit spec draft generated from HTML extraction (review required).
- Verify formulas match the calculator engine and convert any text-only formulas to LaTeX.
- Confirm sources are authoritative and relevant to the calculator methodology.
Affine Cipher Encoder/Decoder
Encrypt or decrypt messages with an affine cipher by setting multiplier and shift keys. Review modular steps per character to validate the mapping.
Affine Cipher Tool
Must be coprime with m (e.g. for m = 26, valid a: 1,3,5,7,9,11,15,17,19,21,23,25).
Any integer. We automatically reduce a and b modulo m.
Modular inverse & key details
Per-character mapping steps
How the Affine Cipher Works
The Affine Cipher is a classical substitution cipher. Each letter is first mapped to a number, transformed with a linear function modulo the alphabet size, and then mapped back to a letter.
Letter-to-number mapping
For the standard English alphabet:
Encryption formula
Let:
- m = size of the alphabet (26 for A–Z)
- a, b = integer keys
- x = numeric value of a plaintext letter
The result E(x) is then converted back to a letter.
Decryption formula
To decrypt, you must compute the modular inverse of a modulo m, denoted a⁻¹, such that:
Then, for each ciphertext letter with numeric value y:
Valid values of a
The cipher is only invertible if a and m are coprime (their greatest common divisor is 1). For the 26-letter alphabet, the valid values of a are:
If you choose an invalid a, this tool will warn you and refuse to decrypt, because no modular inverse exists.
Example: Encrypting “AFFINE CIPHER”
Using keys a = 5, b = 8, m = 26:
- Map letters to numbers: A=0, F=5, I=8, N=13, E=4, C=2, P=15, H=7, R=17.
- Apply E(x) = (5·x + 8) mod 26 to each letter.
- Map the results back to letters.
The tool above shows each step, including the numeric mapping and modular arithmetic, so you can follow the process line by line.
Common Questions
Can I use a custom alphabet?
Yes. Choose “Custom alphabet” and enter any sequence of unique characters. The length of this string becomes the modulus m. This is useful for:
- Including digits (0–9) or punctuation
- Working with non-English alphabets
- Designing puzzle-specific symbol sets
How does this tool handle spaces and punctuation?
By default, spaces, punctuation, and digits are preserved unchanged (they are not encrypted). If you want them to be part of the cipher, include them in a custom alphabet and uncheck “Keep spaces, punctuation, digits”.
Is the Affine Cipher secure?
No. The Affine Cipher is easily broken with frequency analysis or by trying all possible key pairs. It is useful for learning and puzzles, but not for protecting sensitive information.
FAQ
How do I choose good keys a and b?
First pick a value of a that is coprime with the alphabet size m. For A–Z, use one of the 12 valid values listed above. Then choose any integer for b. This tool automatically reduces both a and b modulo m, so you do not need to worry about negative or large values.
What happens if I use an invalid a?
If gcd(a, m) ≠ 1, the mapping is not one-to-one: multiple plaintext letters map to the same ciphertext letter. In that case, decryption is impossible. The calculator detects this and shows an error instead of producing misleading output.
Can I recover the keys from a known plaintext and ciphertext?
In theory, yes: two distinct plaintext–ciphertext letter pairs are enough to solve for a and b. This is one reason the Affine Cipher is weak. This tool focuses on encoding/decoding, but you can use the formulas to solve for a and b manually:
y₂ ≡ a·x₂ + b (mod m)
Subtract the equations to solve for a, then back-substitute to find b.
About the author
Ugo Candido builds financial tools and educational resources to help readers make better money decisions. He focuses on practical, transparent models that reflect how lenders calculate payments and total cost of ownership.
Contact: info@calcdomain.com
Editorial policy
CalcDomain content is created for educational purposes and is reviewed for clarity, accuracy, and transparency. We do not accept paid placements that influence calculator outputs. Inputs and assumptions are shown directly in the interface so you can verify how results are produced.
Methodology
Results use standard formulas and the values you provide. Figures are estimates and may differ from lender quotes. For decisions that require professional guidance, consult a licensed advisor.
Sources
Inputs used by this calculator
- Mode Encrypt
- Decrypt
- Alphabet A–Z (26 letters) Custom alphabet… Custom alphabet Characters must be unique. Alphabet length defines modulus m. Key a (multiplicative) Must be coprime with m (e.g. for m = 26, valid a: 1,3,5,7,9,11,15,17,19,21,23,25). Key b (additive) Any integer. We automatically reduce a and b modulo m. Options Preserve letter case
- Keep spaces, punctuation, digits
- Group ciphertext in blocks of 5
- Show per-character steps
Consistency checks
Checks: non-negative values, plausible ranges, coherent outputs.
Operational notes
Fill in realistic values and keep units and timeframes consistent.
Key entities: Affine, Cipher, Mode Encrypt, Decrypt, Alphabet A–Z (26 letters) Custom alphabet… Custom alphabet Characters must be unique. Alphabet length defines modulus m. Key a (multiplicative) Must be coprime with m (e.g. for m = 26, valid a: 1,3,5,7,9,11,15,17,19,21,23,25). Key b (additive) Any integer. We automatically reduce a and b modulo m. Options Preserve letter case, Keep spaces, punctuation, digits, Group ciphertext in blocks of 5, Show per-character steps.
Inputs used by this calculator
- Mode Encrypt
- Decrypt
- Alphabet A–Z (26 letters) Custom alphabet… Custom alphabet Characters must be unique. Alphabet length defines modulus m. Key a (multiplicative) Must be coprime with m (e.g. for m = 26, valid a: 1,3,5,7,9,11,15,17,19,21,23,25). Key b (additive) Any integer. We automatically reduce a and b modulo m. Options Preserve letter case
- Keep spaces, punctuation, digits
- Group ciphertext in blocks of 5
- Show per-character steps
Consistency checks
Checks: non-negative values, plausible ranges, coherent outputs.
Formula (LaTeX) + variables + units
','
E(x) = (ax + b) \mod m
D(x) = a^{-1}(x - b) \mod m
E(7) = (5 \times 7 + 8) \mod 26
E(7) = (35 + 8) \mod 26
E(7) = 43 \mod 26 = 17
Encoding: $ E(x) = (ax + b) \mod m $ Decoding: $ D(x) = a^{-1}(x - b) \mod m $
$ E(7) = (5 \times 7 + 8) \mod 26 $ $ E(7) = (35 + 8) \mod 26 $ $ E(7) = 43 \mod 26 = 17 $
- No variables provided in audit spec.
- Home — calcdomain.com · Accessed 2026-01-19
https://calcdomain.com/ - Lifestyle & Everyday Calculators — calcdomain.com · Accessed 2026-01-19
https://calcdomain.com/lifestyle-everyday - Hobbies — calcdomain.com · Accessed 2026-01-19
https://calcdomain.com/hobbies
Last code update: 2026-01-19
- Initial audit spec draft generated from HTML extraction (review required).
- Verify formulas match the calculator engine and convert any text-only formulas to LaTeX.
- Confirm sources are authoritative and relevant to the calculator methodology.