# Affine cipher

limit 1000 characters

The affine cipher is a cryptographic technique used to transform plaintext into ciphertext using an affine mathematical function.

The general formula for the affine cipher is C = (aP + b) mod m, where C is the ciphertext, P is the plaintext, a and b are parameters of the affine function, and m is the size of the alphabet used.

Constraints on a and b
To ensure proper encryption, i.e., that each letter of the original message is converted to a different letter in the encrypted message, parameter 'a' must be coprime with m (the number of letters in the alphabet), meaning that the greatest common divisor of a and m must be equal to 1.
Additionally, b must be a positive integer smaller than m, otherwise the affine cipher formula will not work correctly.

In the above calculator, if you enter a value of b that is greater than m, it will be replaced with a congruent value modulo m but smaller than m. For example, if you enter b=28, then this value will be changed to b=2 (where m=26 for the standard alphabet).

## Affine cipher Example

Let's apply the Affine cipher to encrypt the message "HELLO" with the parameters a=3, b=7, and m=26. Using the same method, we get the encrypted message "CTOOX":

• For "H": C = (3*7 + 7) mod 26 = 2, so "C"
• For "E": C = (3*4 + 7) mod 26 = 19, so "T"
• For "L": C = (3*11 + 7) mod 26 = 14, so "O"
• For "L": C = (3*11 + 7) mod 26 = 14, so "O"
• For "O": C = (3*14 + 7) mod 26 = 23, so "X"