How to Encrypt Affine
How to Decrypt Affine
Affine Sample Problem
Encryption uses a classic alphabet, and two integers, called coefficients or keys A and B, these are the parameters of the affine function Ax+B (which is a straight line/linear equation).
Example: Encrypt DCODE with the keys A=5, B=3 and the English/latin alphabet ABCDEFGHIJKLMNOPQRSTUVWXYZ.
For each letter of the alphabet is associated to the value of its position in the alphabet (starting at 0).
Example: By default, A=0, B=1, …, Z=25, it is possible (but not recommended) to use A=1, …, Y=25, Z=0 using the alphabet ZABCDEFGHIJKLMNOPQRSTUVWXY.
For each letter of value x of the plain text, is associated a value y, result of the affine function y = A * x + B mod 26 (with 26 the alphabet size). Each computed value y corresponds to a letter with the same position in the alphabet, it is the ciphered letter. The Affine ciphertext is the replacement of all the letters by the new ones.
Affine decryption requires to know the two keys A and B (the one from encryption) and the used alphabet.
Example: Decrypt the ciphered message SNVSX with keys A=5 and B=3
For each letter of the alphabet, associate the value of its position in the alphabet.
Example: The alphabet ABCDEFGHIJKLMNOPQRSTUVWXYZ, starting at 0 gives A=0, B=1, …, Z=25.
Each letter of value y of the message corresponds to a value x, result of the inverse function x = A′ × (y − B) mod 26 (with 26 the alphabet size)
The value A′ is an integer such as A × A′ = 1 mod 26 (with 26 the alphabet size). To find A′, calculate its modular inverse.
Example: A coefficient A′ for A =5 with an alphabet size of 26 is 21 because 5 * 21 = 105 ≡ 1 mod 26. For S (y = 18), x = A′ × (18 − B) = 21 × (18 − 3) ≡ 315 mod 26 = 3 For each value x, associate the letter with the same position in the alphabet: the coded letter. The plain text is the replacement of all characters with calculated new letters.
Example: For S (x = 3) associate the letter at position 3: D, etc. The original plain text is DCODE.
Choose the best answer: