Affine cipher

The affine cipher is an encryption method. In this method, the plain text, letter by letter, encrypted according to a specific mathematical formula. The affine cipher can without much effort to calculate, but it is, however, not particularly safe. On the one hand, there are only a limited number of secret keys, so that they can all be tried. On the other hand, the ciphertext can be decrypted once the encryption of only two characters is known.

Method

Latin alphabet

This section illustrates the use of the affine cipher for the Latin alphabet with its 26 letters.

Secret key

Transmitter and receiver must agree on a secret key before using the affine cipher. This key is a pair of numbers, wherein one of the numbers 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 or 25 and any number of 0 to 25. For this is true and. is the number of letters of the alphabet.

As an example, encryption and decryption using the key is considered as follows.

Encoding

To encrypt the letters of the alphabet are numbered consecutively: A = 0, B = 1, .... It encrypts each letter individually by adding its number with multiplied and then. The result can then divides by 26

The remainder of this division occurring is the number of the encrypted letter.

If you want to encrypt, for example, the letter S, the number 18 is associated with the key, so we can calculate

The S is then replaced by the L ( the letter with the number 11 ).

Decryption

There is a second number that can be drawn from the following table for each number of the key.

With the numbers and the key can decrypt the ciphertext. It is to the numerical value of the ciphertext letter, calculates and reports the result again by 26

Also in this division occurs a residue, which indicates the number of the character prior to the encryption.

To decrypt, for example, the letter L again, you hit the table and calculated according to

The remainder 18 shows that the letter was originally a S. (You can instead be divided by 26 for negative numbers so often add 26 until you get a positive number. This number is identical to the rest of the division. )

Any alphabet

Instead of the Latin can use any other alphabet. Again, the individual letters are numbered starting with zero. Hereinafter referred to the number of characters of the alphabet.

The secret key is a pair of numbers, wherein both are integers from 0 to. The number must be additionally relatively prime.

For encryption using the modulo operator, which corresponds to the remainder in the division. If the character to be encrypted, then the associated character of the secret text calculated according to the formula

For decryption, we calculate the multiplicative inverse element using the extended Euclidean algorithm. Then you get the original characters from the character of the secret text according to the formula

Shift cipher

When is the affine cipher is called a shift cipher. In a shift is the Caesar cipher.

Security

The affine cipher is a very weak encryption method for longer texts. There are two methods to break them. The easiest way is to try all possible secret key. A faster method can be used when known to two letters in the ciphertext, the corresponding plaintext letter. Then can compute the secret key in a few steps. The two necessary pairs of letters, for example, passes through a frequency analysis.

33191
de