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

PositionInput / P5P + 8mod 26Output
1H / 74317R
2E / 4282C
3L / 116311L
4L / 116311L
5O / 14780A

HELLO with a = 5 and b = 8

InputHELLO
Settingsa = 5; b = 8; A = 0
Expected resultRCLLA
Try this method

Both 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 / C21 × (C − 8)Wrapped PPlain letter
R / 171897H
C / 2-1264E
L / 116311L
L / 116311L
A / 0-16814O

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.

Continue the lesson

Affine cipher toolValid Affine keys and inversesHow modulo 26 wraps around the alphabet