Open the Affine tool, enter HELLO, and choose a = 5 and b = 8. We will use C = (5P + 8) mod 26 to encode all five letters, then undo the calculation to get HELLO back.
1. Check the key
The key a = 5 works because 5 and 26 share no factor other than 1. Its inverse is 21: 5 × 21 = 105, which leaves a remainder of 1 when divided by 26. We will use that inverse when decoding.
2. Encode all five letters
| Position | Input / P | 5P + 8 | mod 26 | Output |
|---|---|---|---|---|
| 1 | H / 7 | 43 | 17 | R |
| 2 | E / 4 | 28 | 2 | C |
| 3 | L / 11 | 63 | 11 | L |
| 4 | L / 11 | 63 | 11 | L |
| 5 | O / 14 | 78 | 0 | A |
HELLO with a = 5 and b = 8
HELLOa = 5; b = 8; A = 0RCLLABoth L letters happen to stay L with this key. A letter can map to itself without being skipped. O becomes A because 5 × 14 + 8 = 78, exactly three times 26.
3. Undo the shift, then the multiplication
Decode with P = 21(C − 8) mod 26. In the tool, keep a = 5 and b = 8; you do not need to enter 21. The decoder works out the inverse for you.
| Cipher letter / C | 21 × (C − 8) | Wrapped P | Plain letter |
|---|---|---|---|
| R / 17 | 189 | 7 | H |
| C / 2 | -126 | 4 | E |
| L / 11 | 63 | 11 | L |
| L / 11 | 63 | 11 | L |
| A / 0 | -168 | 14 | O |
4. See why a = 13 does not work
Change a to 13 and try again. The tool flags the key because A = 0 and C = 2 both become 0 after multiplication modulo 26. Adding b cannot separate those letters again, so there would be no unique way to decode them.
Your turn
With the original valid key, calculate the output of Z. Then check it in the tool.