Tool to decrpt/encrypt with Affine automatically. The Affine cipher uses a encrypting function with additions and multiplication (as the mathematical affine function) which convert a letter (of value x in a 26 letters alphabet) into another letter with value (ax + b) modulo 26.

Affine Cipher - dCode

Tag(s) : Cryptography,Substitution Cipher

dCode is free and its tools are a valuable help in games, puzzles and problems to solve every day!

You have a problem, an idea for a project, a specific need and dCode can not (yet) help you? You need custom development? *Contact-me*!

This page is using the new English version of dCode, *please make comments* !

Sponsored ads

Tool to decrpt/encrypt with Affine automatically. The Affine cipher uses a encrypting function with additions and multiplication (as the mathematical affine function) which convert a letter (of value x in a 26 letters alphabet) into another letter with value (ax + b) modulo 26.

Encryption uses a classic alphabet, and two integers, called coefficients or keys A and B.

Let the alphabet be ABCDEFGHIJKLMNOPQRSTUVWXYZ and keys A=5, B=3. We want to code DCODE.

For each letter of the alphabet is associated to the value of its position in the alphabet.

Beginning with 0, then A = 0, B = 1, Z = 25, but if one wants A = 1, ... Y = 25, Z = 0, then use ZABCDEFGHIJKLMNOPQRSTUVWXY.

For each letter (of value x) of the plain text, is associated a value y, resulting of the affine function y = A*x+B mod 26 (with 26 is the alphabet size)

For D (x=3), y = A*3+B = 5*3+3 = 18

For O (x=14), y = A*14+B = 5*14+3 = 73 = 21 mod 26

For each value y, corresponds a letter with the same position in the alphabet, it is the ciphered letter.

For D (y=18), corresponds letter S (position 18).

For O (y=21), corresponds letter V (position 21).

The Affine cipher text is the replacement of the letters by the new ones.

DCODE becomes SNVSX

Le decryption needs to know the 2 keys A and B and the alphabet.

Let the ciphered message be SNVSX and A=5, B=3 as keys

For each letter of the alphabet corresponds the value of its position in the alphabet.

With the alphabet ABCDEFGHIJKLMNOPQRSTUVWXYZ, beginning with 0, A = 0, B = 1, Z = 25. There is also but A = 1, ... Y = 25 and Z = 0 with the alphabet ZABCDEFGHIJKLMNOPQRSTUVWXY.

For each letter (of value y) of the message, corresponds a value x, result of the inverse function x = A'*(y-B) mod 26 (with 26 is the alphabet size)

The value A' is an integer such as A*A' = 1 mod 26 (with 26 is the alphabet size). To find A', one has to calculate a modular inverse.

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, corresponds a letter with the same position in the alphabet: the coded letter.

For S (x=3), corresponds the letter D (position 3).

The plain texte is the replacement of all characters with calculated new letters.

The original plain text is DCODE.

The ciphered have an indice of coincidence similar to the language of the plain text.

One can crack Affine and find the coefficients by bruteforcing all possible A and B coefficients. Use the Brute-force attack option.

>If the alphabet is 26 characters long, then A coefficient has only 12 possible values, and B has 26 values, so there are only 312 test to try.

The value of A' depends on A but also on the alphabet's lenght, if it is a classic one, it is 26 characters long. The values of A' are then:

A = 1, A' = 1

A = 3, A' = 9

A = 5, A' = 21

A = 7, A' = 15

A = 9, A' = 3

A = 11, A' = 19

A = 15, A' = 7

A = 17, A' = 23

A = 19, A' = 11

A = 21, A' = 5

A = 23, A' = 17

A = 25, A' = 25

No date of known author.

The Bezout's theorem indicates that A' only exists if A and 26 (alphabet length) are coprime. This limits A values to 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 et 25 (if the alphabet is 26 characters long)

Yes, but an automatic decryption process becomes impossible, a single ciphered letter will have multiple plain letters possible.

Yes, but it exists a positive corresponding value, a value of A = -1 is equals to a valeur of A = 25 (because 25 = -1 mod 26).

No, B can take any value.

dCode retains ownership of the source code of the script Affine Cipher. Except explicit open source licence (free / freeware), any algorithm, applet, software (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, translator), or any snippet or function (convert, solve, decrypt, encrypt, decipher, cipher, decode, code, translate) written in PHP (or Java, C#, Python, Javascript, etc.) which dCode owns rights can be transferred after sales quote. So if you need to download the Affine Cipher script for offline use, for you, your company or association, see you on contact page !

- How to encrypt using Affine cipher
- How to decrypt Affine cipher
- How to recognize an Affine ciphered text?
- How to decipher Affine without coefficient?
- Whats are the A' values?
- When Affine have been invented ?
- Why is there a constraint on the value of A?
- Can I use a key A non coprime with 26?
- Can I use a negative value for A?
- Is there a limitation on B value?

affine,function,coefficient,line,modulo,ax,plus,mathematic,addition,multiplication,modular,shift

Source : http://www.dcode.fr/affine-cipher

© 2016 dCode — The ultimate 'toolkit' website to solve every problem. dCode