Home technology Affine cipher

Affine cipher



Introduction

Affinepasswordisareplacementpassword.Itislettertoletter.Itsencryptionfunctionis,whereaandmarerelativelyprime,andmisthenumberofletters.Thedecodingfunctionis,whereisthemultiplicativeinverseelementofainthegroup.

Affinepasswordisatypeofsingle-tableencryption.Alllettersinthealphabetsystemareencryptedbyasimplemathematicalequation,correspondingtonumericalvalues,orbacktoletters.Itstillhastheweaknessesofallalternativepasswords.Alllettersareencryptedbytheequation,andbisthemovingsize.

Inaffineencryption,thelettersystemofsizemfirstcorrespondstoavalueintherangeof0..m-1,andthenmoduloarithmeticisusedtoconvertthelettersintheoriginalfileintothecorrespondingencryptedfileInthenumbers.Theencryptionfunctionofasingleletteris

Theremaindermisthesizeofthelettersystemandaandbarethekeyvalues​​ofthepassword.Thevalueofamustbesuchthataandmarerelativelyprime.Thedecryptionequationis

wheretheequationissatisfied.

Themultiplicativeinverseelementofaonlyexistswhenaandmarerelativelyprime.Therefore,thereisnorestrictionofa,anddecryptionmaynotbepossible.Itiseasytoknowthatthedecryptionequationisinversetotheencryptionequation.

Disadvantages

Becausetheaffinecipherisstillasinglealphabetcipher,itstillretainstheweaknessofthistypeofencryption.Whena=1,affineencryptionistheCaesarcipher,becausetheencryptionequationcanbesimplifiedtolinearmovement.ConsiderencryptingEnglish.(Ie:m=26),excluding26andCaesarciphers,thereareatotalof286affineciphers.Thisvalueisduetothefactthat12numbersand26arerelativelyprimeamongnumberslessthan26.Eachvalueofacanhave26mutuallydifferentadditivemoves(thevalueofb);therefore,thereare12*26or312possiblekeyvalues​​intotal.Becausethepasswordlackscomplexity,accordingtoKirkhoff'sprinciple,thissystemisinsecure.

Theprimaryweaknessofthispasswordisthatifacryptographercandiscover(suchasfrequencyanalysis,bruteforcecracking,speculationoranyothermethod)thetwo-characteroriginaltextoftheencrypteddocument,thekeyvaluecanbesolvedAsystemofequationsisobtained.Sinceweknowthataandmarerelativelyprime,thisfactcanbeusedtoquicklycrackapassword.

Thesamekindofconversioninaffinecryptographyisusedinthelinearpseudorandomgenerator,whichisoneofthepseudorandomnumbergenerators.Thisgeneratorisnotasecureencryptedvirtualrandomnumbergenerator,becausetheaffinepasswordisnotsecure.

Example

Inthefollowingexampleofencryptionanddecryption,thelettersarefromAtoZ,andtheyallhavecorrespondingvalues​​inthetable.

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

Encryption

Intheencryptionexample,usethevaluecorrespondingtoeachletterintheprecedingtabletoknowthattheoriginalfiletobeencryptedis"AFFINECIPHER",acorrespondsto5,bcorrespondsto8,andmcorrespondsto26(becauseatotalof26lettersareused).Allpossiblevalues​​ofaare1,3,5,7,9,11,15,17,19,21,23,and25.Ifaisnotequalto1,thevalueofbcanberandomlyselected,sothefunctionofthisencryptionexampleis.Thefirststepinencryptingamessageistowriteoutthenumericvalueofeachletter.

Originalfile:

A

td>

F

F

I

N

E

C

I

P

H

E

R

x:

0

5

5

8

13

4

2

8

15

7

4

17

Now,takethevalues​​ofxandsolvethefirstpartoftheequation,(5x+8).Afterobtainingthevaluecorrespondingtoeachletter(5x+8),taketheremainderof26.Thefollowingtableshowsthefirstfourstepsofencryption.

Originalfile:

A

td>

F

F

I

N

E

C

I

P

H

E

R

x

0

5

5

8

13

4

2

8

15

7

4

17

5x+8

8

33

33

48

73

28

18

48

83

43

28

93

(5x+8)mod26

8

7

7

22

21

2

18

22

5

17

2

15

ThelaststepofencryptingthemessageistofindthecorrespondingletterNumericalvalue.Inthisexample,theencryptedtextshouldbeIHHWVCSWFRCP.Thefollowingtableshowsthecompletetableofaffineencryptionamessage.

Originalfile:

A

td>

F

F

I

N

E

C

I

P

H

E

R

x

0

5

5

8

13

4

2

8

15

7

4

17

5x+8

8

33

33

48

73

28

18

48

83

43

28

93

(5x+8)pmod26

8

7

7

22

21

2

18

22

5

17

2

15

Encryptedfiles:

I

H

H

W

V

C

S

W

F

R

C

P

Decryption

Inthisdecryptionexample,theencryptedfiletobedecryptedcomesfromtheencryptionexample.Thedecryptionequationis.Aftercalculation,a-1is21,bis8,andmis26.Atthebeginning,writedownthevalueofeachletterintheencryptedfile,asshowninthefollowingtable:

ciphertext:

I

H

H

W

V

C

S

W

F

R

C

P

y:

8

7

7

22

21

2

18

22

5

17

2

15

Next,calculate21(y-8),andthentaketheremainderofdividingtheresultby26.Thefollowingtableshowstheresultsofthetwocalculations.

Ciphertext:

I

H

H

W

V

C

S

W

F

R

C

P

y:

8

7

7

22

21

2

18

22

5

17

2

15

21(y-8):

0

-21

-21

294

273

-126

210

294

-63

189

-126

147

(21(y-8))mod26:

0

5

5

8

13

4

2

8

15

7

4

17

Thelaststepofdecryptionistousetheformtoconvertthevaluebacktotheletter.ThedecryptedoriginalfileisAFFINECIPHER.Thefollowingisthedecryptedtable:

Encryptedfile:

I

H

H

W

V

C

S

W

F

R

C

P

y:

8

7

7

22

21

2

18

22

5

17

2

15

21(y-8):

0

-21

-21

294

273

-126

210

294

-63

189

-126

147

(21(y-8))mod26:

0

5

5

8

13

4

2

8

15

7

4

17

Originalfile:

A

F

F

I

N

E

C

I

P

H

E

R

Encryptallletters

Forfasterencryptionanddecryption,allletterscanbeencryptedtomapthelettersoftheoriginalfiletotheencryptedfileone-to-one.Inthisexample,theone-to-onemappingisasfollows:

Thelettersintheoriginaldocument

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

Numberintheoriginalfile

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

(5x+8)mod(26)

8

13

18

23

2

7

12

17

22

1

6

11

16

21

0

5

10

15

20

25

4

9

14

19

24

3

Encryptedfileletter

I

N

S

X

C

H

M

R

W

B

G

L

Q

V

A

F

K

P

U

Z

E

J

O

T

Y

D

Programexample

UsingPythonprogramminglanguage,thefollowingcodesareavailableToencrypttheRomanlettersAtoZ.

#Printthealphabetoftheaffinepassword.#Amustandmmutualqualitydefaffine(a,b):foriinrange(26):printchr(i+65)+":"+chr(((a*i+b)%26)+65)#Examplesofcallingfunctionsaffine(5,8)

OrtakeJavaasanexample:

publicvoidAffine(inta,intb){for(intnum=0;num

This article is from the network, does not represent the position of this station. Please indicate the origin of reprint
TOP