Affine cipher

Time:2021-1-19

Affine cipher

The idea of affine cryptography is to multiply the plaintext by a part of the key, and then add the rest of the key.

Suppose x, y, a, B, Z_ {26}\\

Decryption can be easily derived from encryption functions

a·x+b\equiv y\ mod\ 26\\
a·x\equiv (y-b)\ mod \ 26\\
x\equiv a^{-1}·(y-b)\ mod\ 26

The restriction GCD (a, 26) = 1 comes from the fact that it is necessary to find the inverse of key parameter a when decrypting. If the inverse exists, element a and modulus must be coprime. Therefore, a must be in the following set:

a\in \left\{1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25 \right\}

So, how do we find ita^{-1}At present, we can only get it by trial and error method: for a given a, we only need to try all possible values oncea^{-1}Until you get:

a·a^{-1}\equiv 1\ mod\ 26

This work adoptsCC agreementReprint must indicate the author and the link of this article


Hacking

Recommended Today

Swift advanced (XV) extension

The extension in swift is somewhat similar to the category in OC Extension can beenumeration、structural morphology、class、agreementAdd new features□ you can add methods, calculation attributes, subscripts, (convenient) initializers, nested types, protocols, etc What extensions can’t do:□ original functions cannot be overwritten□ you cannot add storage attributes or add attribute observers to existing attributes□ cannot add parent […]