The encryption function for a single letter is where modulus m is the size of the alphabet and a and b are the keys of the cipher.
This lack of variety renders the system as highly insecure when considered in light of Kerckhoffs' Principle.
The cipher's primary weakness comes from the fact that if the cryptanalyst can discover (by means of frequency analysis, brute force, guessing or otherwise) the plaintext of two ciphertext characters then the key can be obtained by solving a simultaneous equation.
In this example showing encryption and decryption, the alphabet is going to be the letters A through Z, and will have the corresponding values found in the following table.
The final step in encrypting the message is to look up each numeric value in the table for the corresponding letters.
To begin, write the numeric equivalents to each letter in the ciphertext, as shown in the table below.
The final step in decrypting the ciphertext is to use the table to convert numeric values back into letters.
In this example, the one-to-one map would be the following: The following Python code encrypts text with the affine cipher: