Tool to decrypt/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) : Poly-Alphabetic Cipher

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

A suggestion ? a feedback ? a bug ? an idea ? *Write to dCode*!

Tool to decrypt/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, these are the parameters of the affine function Ax+B.

__Example:__ Encrypt DCODE with the alphabet ABCDEFGHIJKLMNOPQRSTUVWXYZ and keys A=5, B=3.

For each letter of the alphabet is associated to the value of its position in the alphabet (start at 0).

__Example:__ A=0, B=1,..., Z=25. It is possible to use A=1, ..., Y=25, Z=0 with the alphabet ZABCDEFGHIJKLMNOPQRSTUVWXY (not recommended).

For each letter of value $ x $ of the plain text, is associated a value $ y $, resulting of the affine function $ y = A \times x + B \mod 26 $ (with $ 26 $ the alphabet size). For each value $ y $, corresponds a letter with the same position in the alphabet, it is the ciphered letter. The **Affine** ciphertext is the replacement of the letters by the new ones.

__Example:__ DCODE is crypted SNVSX

Plain letter | $ x $ | $ y $ | Cipher letter |

D | 3 | $ 5 \times 3 + 3 = 18 $ | S |

O | 14 | $ 5 \times 14 + 3 = 73 = 21 \mod 26 $ | V |

**Affine** decryption requires to know the two keys A and B and the alphabet.

__Example:__ Decrypt the ciphered message SNVSX with keys A=5 and B=3

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

__Example:__ The alphabet ABCDEFGHIJKLMNOPQRSTUVWXYZ, starting at 0 gives A=0, B=1, ..., Z=25. There is also 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' \times (y-B) \mod 26 $ (with $ 26 $ the alphabet size)

The value $ A' $ is an integer such as $ A \times A' = 1 \mod 26 $ (with $ 26 $ the alphabet size). To find $ A' $, calculate a modular inverse.

__Example:__ A coefficient $ A' $ for $ A = 5 $ with an alphabet size of $ 26 $ is $ 21 $ because $ 5 \times 21 = 105 \equiv 1 \mod 26 $.

For S ( $ y=18 $ ), $ x = A' \times (18-B) = 21*(18-3) \equiv 315 \mod 26 = 3 $

For each value $ x $, corresponds a 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 $ ) corresponds the letter at position 3: D, etc. The original plain text is DCODE.

A message encrypted by **Affine** has a coincidence index close to the plain text language's one.

Any reference to an affine function (in a straight line), a graph, an abscissa or an ordinate is a clue.

The Caesar cipher is a special case of the **Affine cipher** where A is 1 and B is the offset.

To crack **Affine**, it is possible to bruteforce/test all values for 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.

Calculate the modular inverse of A, modulo the length of the alphabet.

B' has the same value as B.

The value of A' depends on A but also on the alphabet's length, 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 |

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 and 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 value of A = 25 (because 25 = -1 mod 26).

In mathematics, an affine function is defined by addition and multiplication of the variable (often $ x $) and written $ f (x) = ax + b $. The **affine cipher** is similar to the $ f $ function as it uses the values $ a $ and $ b $ as a coefficient and the variable $ x $ is the letter to be encrypted.

No date of known author.

dCode retains ownership of the source code of the script Affine Cipher online. Except explicit open source licence (indicated Creative Commons / free), any algorithm, applet, snippet, software (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, translator), or any function (convert, solve, decrypt, encrypt, decipher, cipher, decode, code, translate) written in any informatic langauge (PHP, Java, C#, Python, Javascript, Matlab, etc.) which dCode owns rights will not be released for free. To download the online Affine Cipher script for offline use on PC, iPhone or Android, ask for price quote on contact page !

- Affine Decoder
- Affine Encoder
- How to encrypt using Affine cipher
- How to decrypt Affine cipher
- How to recognize an Affine ciphertext?
- How to decipher Affine without coefficient A and B?
- How to compute A' value?
- How to compute B' value?
- What are the A' values?
- Why is there a constraint on the value of A?
- Is it possible to use a key A not coprime with 26?
- Does a negative value for A exists?
- Is there a limitation on B value?
- Why is this encryption so called affine?
- When Affine have been invented ?

affine,function,coefficient,line,modulo,ax,plus,mathematic,addition,multiplication,modular,shift,graphic,graph,ordinate,abscissa

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

© 2020 dCode — The ultimate 'toolkit' to solve every games / riddles / geocaching / CTF.

Feedback

▲