Skip to document

Affine Cipher

Cryptography - Affine Cipher
Course

Computer Science (ICS 2103)

335 Documents
Students shared 335 documents in this course
Academic year: 2021/2022
Uploaded by:
Anonymous Student
This document has been uploaded by a student, just like you, who decided to remain anonymous.
Meru University of Science and Technology

Comments

Please sign in or register to post comments.

Preview text

Math 135 (Summer 2006) Affine Ciphers, Decimation Ciphers, and Modular Arithmetic

Affine Ciphers

An encipherment scheme (or algorithm) of the form

E(x) = (ax+b) MOD 26

is called anaffine cipher. Herexis the numerical equivalent of the given plaintext letter, andaand bare (appropriately chosen) integers.

Recall that the numerical equivalents of the letters are as follows:

A B C D E F G H I J K L M 0 1 2 3 4 5 6 7 8 9 10 11 12 N O P Q R S T U V W X Y Z 13 14 15 16 17 18 19 20 21 22 23 24 25

Example: EncipherITS COOLwith

E(x) = (5x+ 8) MOD 26.

Solution: Filling in the following table gives

plain I T S C O O L x 8 19 18 2 14 14 11 5 x+ 8 48 103 98 18 78 78 63 (5x+ 8) MOD 26 22 25 20 18 0 0 11 cipher W Z U S A A L

Ify=E(x) = (ax+b) MOD 26, then we can “solve forxin terms ofy” and so determineE− 1 (y). That is, ify≡(ax+b) (mod 26), theny−b≡ax(mod 26), or equivalentlyax≡(y−b) (mod 26). Using our earlier results, we see that if we multiply both sides bya− 1 (mod 26), thenx≡a− 1 (y−b) (mod 26) and so our decipherment function is

E− 1 (y) =a− 1 (y−b) MOD 26.

Example: DecipherHPCCXAQif the encipherment function isE(x) = (5x+ 8) MOD 26.

Solution: We begin by finding the decipherment function. Since 5x ≡ 1 (mod 26) is solved with x≡21 (mod 26) we see 5− 1 (mod 26) = 21. Therefore,

E− 1 (y) = 21(y−8) MOD 26

and so filling in our table gives

cipher H P C C X A Q y 7 15 2 2 23 0 16 y− 8 -1 7 -6 -6 15 -8 8 21(y−8) -21 147 -126 -126 315 -168 168 21(y−8) MOD 26 5 17 4 4 3 14 12 plain F R E E D O M

Example: Suppose that an affine cipherE(x) = (ax+b) MOD 26 enciphersHasXandQasY. Find the cipher (that is, determineaandb).

Solution: We see that

H7→XmeansE(7) = 23 andQ7→YmeansE(16) = 24.

That is,

a·7 +b≡23 (mod 26) anda·16 +b≡24 (mod 26).

Subtracting gives 16a− 7 a≡1 (mod 26) so that 9a≡1 (mod 26). Therefore,a= 9− 1 (mod 26) = 3. Finally, we substitutea= 3 into either of the earlier equations and solve forb,

i., 3·7 +b≡23 (mod 26) impliesb= 2.

In summary, E(x) = (3x+ 2) MOD 26.

Remark: (The “Mod-mod Connection”) The least non-negative solution of the congruencex≡b(modm) isx=bMODm.

Decimation Ciphers

In the special case whereb= 0, the affine cipherE(x) =axMODmis called adecimation cipher. This is discussed in detail on pages 70–73. The key idea in this subsection is that certain choices ofa andmdo not lead to valid substitutions.

Example: Suppose thatE(x) = 4xMOD 26. Determine the ciphertext alphabet.

Solution: We begin with our table of numerical equivalents, and then determine 4xMOD 26.

plain 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 4 xx 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 250 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 4 xMOD 26 0 4 8 12 16 20 24 2 6 10 14 18 22 0 4 8 12 16 20 24 2 6 10 14 18 22 cipher A E I M Q U Y C G K O S W A E I M Q U Y C G K O S W

The problem, of course, is that 4 and 26 arenotrelatively prime, and so this cyclic phenomenon occurs in the cipher alphabet. Since the numbers 0, 2 , 4 , 6 , 8 , 10 , 12 , 13 , 14 , 16 , 18 , 20 , 22 ,24 are not relatively prime with respect to the 26, the only possible choices for the decimation cipherE(x) =axMOD 26 area= 1, 3 , 5 , 7 , 9 , 11 , 15 , 17 , 19 , 21 , 23 ,25. Therefore, we conclude that the decimation cipher is weaker than the simple shift cipher. If the cryptanalyst knows that a shift cipher has been used, then there are 25 possible shifts that need to be checked. However, if it is knownthat a decimation cipher has been used, then there are only 12 possible ciphers that need to be checked.

Summary of Valid Affine Ciphers

The functionE(x) = (ax+b) MOD 26 defines a valid affine cipher ifais relatively prime to 26, andb is an integer between 0 and 25, inclusive. Ifb= 0, then we refer to this cipher as a decimation cipher. (Note that since there are 12 valid choices ofaand 26 valid choices ofb, there are 12×26 = 312 possible valid affine ciphers.)

Also note that ifa= 1, thenE(x) = (x+b) MOD 26 is simply a Caesar (+b) shift cipher.

Was this document helpful?

Affine Cipher

Course: Computer Science (ICS 2103)

335 Documents
Students shared 335 documents in this course
Was this document helpful?
Math 135 (Summer 2006)
Affine Ciphers, Decimation Ciphers, and Modular Arithmetic
Affine Ciphers
An encipherment scheme (or algorithm) of the form
E(x) = (ax +b) MOD 26
is called an affine cipher. Here xis the numerical equivalent of the given plaintext letter, and aand
bare (appropriately chosen) integers.
Recall that the numerical equivalents of the letters are as follows:
ABCDEFGHIJKLM
0 1 2 3 4 5 6 7 8 9 10 11 12
NOPQRSTUVWXYZ
13 14 15 16 17 18 19 20 21 22 23 24 25
Example: Encipher ITS COOL with
E(x) = (5x+ 8) MOD 26.
Solution: Filling in the following table gives
plain I T S C O O L
x8 19 18 2 14 14 11
5x+ 8 48 103 98 18 78 78 63
(5x+ 8) MOD 26 22 25 20 18 0 0 11
cipher W Z U S A A L
If y=E(x) = (ax +b) MOD 26, then we can “solve for xin terms of y and so determine E1(y). That
is, if y(ax +b) (mod 26), then ybax (mod 26), or equivalently ax (yb) (mod 26). Using
our earlier results, we see that if we multiply both sides by a1(mod 26), then xa1(yb) (mod 26)
and so our decipherment function is
E1(y) = a1(yb) MOD 26.
Example: Decipher HPCCXAQ if the encipherment function is E(x) = (5x+ 8) MOD 26.
Solution: We begin by finding the decipherment function. Since 5x1 (mod 26) is solved with
x21 (mod 26) we see 51(mod 26) = 21. Therefore,
E1(y) = 21(y8) MOD 26
and so filling in our table gives
cipher H P C C X A Q
y7 15 2 2 23 0 16
y8-1 7 -6 -6 15 -8 8
21(y8) -21 147 -126 -126 315 -168 168
21(y8) MOD 26 5 17 4 4 3 14 12
plain F R E E D O M