Affine Cipher Input Panel
Valid values for key a include: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25.
Example Data Table
| Input | Mode | Key a | Key b | Output | Notes |
|---|---|---|---|---|---|
| HELLO WORLD | Encrypt | 5 | 8 | RCLLA OAPLX | Classic uppercase example with preserved spacing. |
| RCLLA OAPLX | Decrypt | 5 | 8 | HELLO WORLD | Reverse operation using the modular inverse. |
| AFFINE CIPHER | Encrypt | 5 | 8 | IHHWVC SWFRCP | Useful for checking repeated letters and spacing. |
| MATH TOOL | Encrypt | 7 | 2 | ICFZ FWWB | Shows a different valid multiplier key. |
Formula Used
Encryption: C = (aP + b) mod m
Decryption: P = a-1(C - b) mod m
Alphabet size: m = 26
Here, P is the plaintext index, C is the ciphertext index, a is the multiplicative key, b is the additive key, and a-1 is the modular inverse of a. The condition gcd(a, 26) = 1 must hold, or decryption fails.
How to Use This Tool
- Enter the text you want to transform.
- Select Encrypt or Decrypt.
- Enter key a and key b.
- Use a value for a that is coprime with 26.
- Choose whether to preserve case, spaces, and punctuation.
- Click Submit to generate the transformed output.
- Review the step table, summary metrics, and frequency graph.
- Download the results as CSV or PDF when needed.
Frequently Asked Questions
1. What is an affine cipher?
An affine cipher is a monoalphabetic substitution method. It maps each letter index through a linear modular equation using multiplication and addition.
2. Why must key a be coprime with 26?
Key a needs a modular inverse for decryption. If gcd(a, 26) is not 1, the inverse does not exist, and the mapping becomes non-reversible.
3. How does decryption work here?
The tool first finds the modular inverse of a. It then applies P = a inverse times (C minus b), all reduced modulo 26.
4. Are spaces and punctuation encrypted?
Only letters are transformed. Spaces, punctuation, and digits can either stay unchanged or be removed, depending on the option you select.
5. Can I preserve lowercase letters?
Yes. Enable the preserve case option, and the tool will return lowercase output for lowercase input letters.
6. What does the Plotly chart show?
The chart compares input and output letter frequencies. It helps you inspect how the affine mapping redistributes character counts across the alphabet.
7. Is the affine cipher secure for modern protection?
No. It is useful for learning classical cryptography, modular arithmetic, and substitution systems, but it is far too weak for modern secure communication.
8. When should I use this tool?
Use it for coursework, demonstrations, cipher exercises, manual verification, and quick experiments involving modular linear transformations on alphabetic text.