Clever Geek Handbook
📜 ⬆️ ⬇️

Affine code

An affine cipher is a special case of a more general mono-alphabetic substitution cipher . Substitution ciphers also include Caesar's cipher , ROT13, and Atbash . Since the affine cipher is easy to decrypt, it has weak cryptographic properties [1] .

Description

In the affine code for each letter of the size alphabetm {\ displaystyle m} m is assigned a number from the range0 ..m-one {\ displaystyle 0..m-1} 0 .. m-1 . Then, using modular arithmetic for each number corresponding to the letter of the original alphabet, a new number is calculated that will replace the old one in the ciphertext. Encryption Function [2] for each letter

E(x)=(ax+b)modm,{\ displaystyle {\ mbox {E}} (x) = (ax + b) \ mod {m},} \mbox{E}(x)=(ax+b)\mod{m},

where is the modulem {\ displaystyle m} m Is the size of the alphabet, and the paira {\ displaystyle a} a andb {\ displaystyle b} b - cipher key. Valuea {\ displaystyle a} a should be chosen such thata {\ displaystyle a} a andm {\ displaystyle m} m - mutually prime numbers . Decryption Function [2]

D(x)=a-one(x-b)modm,{\ displaystyle {\ mbox {D}} (x) = a ^ {- 1} (xb) \ mod {m},} \mbox{D}(x)=a^{-1}(x-b)\mod{m},

Wherea-one {\ displaystyle a ^ {- 1}} a^{{-1}} - converse toa {\ displaystyle a} a modulo numberm {\ displaystyle m} m . That is, it satisfies the equation [2]

one=aa-onemodm.{\ displaystyle 1 = aa ^ {- 1} \ mod {m}.} {\displaystyle 1=aa^{-1}\mod {m}.}

Converse toa {\ displaystyle a} a a number exists only whena {\ displaystyle a} a andm {\ displaystyle m} m - mutually simple. So, in the absence of restrictions on the choice of numbera {\ displaystyle a} a decryption may not be possible. We show that the decryption function is inverse to the encryption function

D(E(x))=a-one(E(x)-b)modm=a-one(((ax+b)modm)-b)modm=a-one(ax+b-b)modm=a-oneaxmodm=xmodm.{\ displaystyle {\ begin {matrix} {\ mbox {D}} ({\ mbox {E}} (x)) & = & a ^ {- 1} ({\ mbox {E}} (x) -b) \ mod {m} \\ & = & a ^ {- 1} (((ax + b) \ mod {m}) - b) \ mod {m} \\ & = & a ^ {- 1} (ax + bb ) \ mod {m} \\ & = & a ^ {- 1} ax \ mod {m} \\ & = & x \ mod {m}. \ end {matrix}}} \begin{matrix}\mbox{D}(\mbox{E}(x)) &= &a^{-1}(\mbox{E}(x)-b)\mod{m}\\
                             &= &a^{-1}(((ax+b)\mod{m})-b)\mod{m} \\
                             &= &a^{-1}(ax+b-b)\mod{m} \\
                             &= &a^{-1}ax \mod{m}\\
                             & = &x\mod{m}.
\end{matrix}

The number of possible keys for an affine cipher can be written through the Euler function asφ(m)m {\ displaystyle \ varphi (m) m} \varphi(m)m [1] .

Encryption and Decryption Examples

The following examples use Latin letters from A to Z, the corresponding numerical values ​​are shown in the table.

ABCDEFGHIJKLMNOPQRSTUVWXYZ
0one23fourfive67eight9teneleven12131415sixteen1718nineteen202122232425

Encryption

In this example, the message "ATTACK AT DAWN" must be encrypted using the above correspondence between letters and numbers, and the valuesa=3 {\ displaystyle a = 3}   ,b=four {\ displaystyle b = 4}   andm=26 {\ displaystyle m = 26}   , since the alphabet used is 26 letters. Only on the numbera {\ displaystyle a}   restrictions are imposed, since it must be mutually simple with 26. Possible valuesa {\ displaystyle a}   : 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 and 25 [3] . Valueb {\ displaystyle b}   can be anything only ifa {\ displaystyle a}   not equal to one, since this is a shift of the cipher. So, for our example, the encryption functiony=E(x)=(3x+four)(mod26) {\ displaystyle y = E (x) = (3x + 4) {\ pmod {26}}}   . The first step in encryption is to record numbers corresponding to each letter of the message.

messageATTBUTCKATDAWN
x{\ displaystyle x}  0nineteennineteen02ten0nineteen302213

Now, for each valuex {\ displaystyle x}   find the value(3x+four) {\ displaystyle (3x + 4)}   . After finding the value(3x+four) {\ displaystyle (3x + 4)}   for each character we take the remainder of the division(3x+four) {\ displaystyle (3x + 4)}   at 26. The following table shows the first four steps of the encryption process.

messageATTBUTCKATDAWN
x{\ displaystyle x}  0nineteennineteen02ten0nineteen302213
3x+four{\ displaystyle 3x + 4}  four6161fourten34four6113four7043
(3x+four)(mod26){\ displaystyle (3x + 4) {\ pmod {26}}}  four99fourteneightfour913four1817

The last step of the encryption process is to substitute the letter corresponding to it instead of each number. In this example, the ciphertext will be "EJJEKIEJNESR". The table below shows all steps for encrypting a message with an affinity cipher.

messageATTBUTCKATDAWN
x{\ displaystyle x}  0nineteennineteen02ten0nineteen302213
3x+four{\ displaystyle 3x + 4}  four6161fourten34four6113four7043
(3x+four)(mod26){\ displaystyle (3x + 4) {\ pmod {26}}}  four99fourteneightfour913four1817
ciphertextEJJEKIEJNESR

Decryption

For decryption, we take the ciphertext from the encryption example. Decryption function willD(y)=a-one(y+m-b)modm {\ displaystyle {\ mbox {D}} (y) = a ^ {- 1} (y + mb) {\ mbox {mod}} m}   wherea-one=9 {\ displaystyle a ^ {- 1} = 9}   ,b=four {\ displaystyle b = 4}   andm=26 {\ displaystyle m = 26}   .

Note: if eachy⩾b {\ displaystyle y \ geqslant b}   , then the decryption function takes the formD(y)=a-one(y-b)modm {\ displaystyle {\ mbox {D}} (y) = a ^ {- 1} (yb) {\ mbox {mod}} m}   . (In the same way as in the reviewed example, but we will analyze the general version)

First, write down the numerical values ​​for each letter of the ciphertext, as shown in the table below.

ciphertextEJJEKIEJNESR
y{\ displaystyle y}  four99fourteneightfour913four1817

Now for everyoney {\ displaystyle y}   need to calculate9(y+m-four) {\ displaystyle 9 (y + m-4)}   and take the remainder of dividing this number by 26. The following table shows the result of these calculations.

ciphertextEJJEKIEJNESR
y{\ displaystyle y}  four99fourteneightfour913four1817
9(y+26-four){\ displaystyle 9 (y + 26-4)}  234279279234288270234279315234360351
9(y+26-four)(mod26){\ displaystyle 9 (y + 26-4) {\ pmod {26}}}  0nineteennineteen02ten0nineteen302213

The last step of the decryption operation for ciphertext is to match the letter numbers. The message after decryption will be "ATTACKATDAWN". The table below shows the completion of the last step.

ciphertextEJJEKIEJNESR
y{\ displaystyle y}  four99fourteneightfour913four1817
9(y+26-four){\ displaystyle 9 (y + 26-4)}  234279279234288270234279315234360351
9(y+26-four)(mod26){\ displaystyle 9 (y + 26-4) {\ pmod {26}}}  0nineteennineteen02ten0nineteen302213
messageATTACKATDAWN

Encryption of the entire alphabet

To speed up encryption and decryption, you can perform the encryption procedure for all letters of the alphabet and get a table of correspondences between the letters of the original message and the ciphertext. For the examples used above, such a table will look like this:

message letterABCDEFGHIJKLMNOPQRSTUVWXYZ
x{\ displaystyle x}  0one23fourfive67eight9teneleven12131415sixteen1718nineteen202122232425
(3x+four)(mod26){\ displaystyle (3x + 4) {\ pmod {26}}}  four7ten13sixteennineteen22252fiveeighteleven1417202303691215182124one
ciphertext letterEHKNQTWZCFILORUXADGJMPSVYB

Cryptanalysis

Since the affine cipher is essentially a mono- alphabetical replacement cipher , it has all the vulnerabilities of this class of ciphers. Caesar's cipher is an affine cipher witha=one {\ displaystyle a = 1}   , which reduces the encryption function to a simple linear shift [1] .

In the case of encryption of messages in Russian (i.e.m=33 {\ displaystyle m = 33}   ) there are 297 non-trivial affine ciphers, not including the 33 trivial Caesar ciphers. This number is easy to calculate, knowing that there are only 20 numbers coprime with 33 and less than 33 (and this is the possible valuea {\ displaystyle a}   ) To each valuea {\ displaystyle a}   may correspond to 33 different additional shifts (valueb {\ displaystyle b}   ); that is, there are 20 * 33 or 660 possible keys in total. Similarly, for messages in English (i.e.m=26 {\ displaystyle m = 26}   ) in total there are 12 * 26 or 312 possible keys [3] . Such a limited number of keys leads to the fact that the system is extremely non-cryptographic in terms of the Kirkhoffs principle .

The main vulnerability of a cipher is that a cryptanalyst can figure out (by frequency analysis [4] , exhaustive search [1] , guessing, or in some other way) the correspondence between any two letters of the source text and ciphertext. Then the key can be found by solving the system of equations [4] . In addition, so we know thata {\ displaystyle a}   andm {\ displaystyle m}   - mutually simple, this allows you to reduce the number of keys checked for a complete search.

A transformation similar to an affine cipher is used in the linear congruent method [5] (a type of pseudo-random number generator ). This method is not cryptographic for the same reason as an affinity cipher.

Notes

  1. ↑ 1 2 3 4 SR Nagpaul, Surender Kumar Jain. Topics in applied abstract algebra . - AMS. - P. 137-138.
  2. ↑ 1 2 3 Johannes Buchmann. Introduction to cryptography . - Springer. - P. 95.
  3. ↑ 1 2 David Salomon. Coding for data and computer communications . - Springer. - P. 204.
  4. ↑ 1 2 Josef Pieprzyk, Thomas Hardjono, Jennifer Seberry. Fundamentals of computer security . - Springer, 2003 .-- P. 72-74. - 677 p.
  5. ↑ Algorithms: an introduction to development and analysis . - Williams Publishing House. - S. 130-131.
Source - https://ru.wikipedia.org/w/index.php?title=Affine_Cipher&oldid=89179152


More articles:

  • Polyana (Kharkiv region)
  • P-105D
  • Missulena
  • Taseeva
  • Hilda Ennings
  • Sybyzgy
  • Moshkovsky rural settlement (Tver region)
  • Pleocomidae
  • Vjesnik
  • Lacalle de Herrera, Luis Alberto

All articles

Clever Geek | 2019