Lecture 15 Affine Cipher

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Information Security

Delivered By: Dr.Ahthasham


Dated: 11th Nov 2023
Email: [email protected]
Affine Cipher
• The Affine Cipher is another example of a Monalphabetic Substitution
cipher, since the encryption process is substantially mathematical. The
whole process relies on working modulo m (the length of the alphabet used).
By performing a calculation on the plaintext letters, we encipher the
plaintext.

• Addition (shifting) and multiplication can be combined to give an Affine


transformation.
Encryption
• The first step in the encryption process is to transform each of the letters in the
plaintext alphabet to the corresponding integer in the range 0 to m-1. With this
done, the encryption process for each letter is given by
E(x) = (ax + b) mod m
• where a and b are the key for the cipher. This means that we multiply our integer
value for the plaintext letter by a, and then add b to the result. Finally, we take this
modulus m (that is we take the remainder when the solution is divided by m, or we
take away the length of the alphabet until we get a number less than this length).
Example
• As an example, let us encrypt the plaintext "affine cipher", using the
key a = 3, b = 4.
E(x) = (ax + b) mod m

• In this instance, the calculation needed is (3x+4). Finally, we must ensure


that all our answers are calculated mod 26 and convert the integers back
to ciphertext letters.
Plain A F F I N E C I P H E R
Text
X 0 5 5 8 13 4 2 8 15 7 4 17
3X+4 4 19 19 28 43 16 10 28 49 25 16 55
3X+4 4 19 19 2 17 16 10 2 23 25 16 3
Mod 26
Cipher E T T C R Q K C X Z Q D
Txt
Cipher 4 19 19 2 17 16 10 2 23 25 16 3
Value
Decryption:
Step 1: How to find inverse of a with mod 26?

Example: (a) 3 × (Any #) mod 26 =1, i.e. 3 × 35 mod(26) =1

(LHS)(3 × 35 = 105 Mod(26) =1 = (RHS) 4 × 26 + 1 ≡ 105 mod (26)=1).

Step 2: We must now perform the inverse calculations on the integer


values of the ciphertext. 35(y - 4) mod (26) to get integer value again.
Cipher E T T C R Q K C X Z Q D
Text
C 4 19 19 2 17 16 10 2 23 25 16 3
Value 4 19 19 28 43 16 10 28 49 25 16 55
35(Y-4) 0 525 525 840 1365 420 210 840 1575 735 420 1785
35 (Y-4) 0 5 5 8 13 4 2 8 15 7 4 17
mod 26
Plain A F F I N E C I P H E R
Text
Letter
Practice 01
• As an example, let us encrypt the plaintext "affine cipher", using the
key a = 5, b = 8
E(x) = (ax + b) mod m
In this instance, the calculation needed is (5x+8). Finally, we must ensure that all
our answers are calculated mod 26 and convert the integers back to ciphertext
letters. All this information is shown in the table below.
Decryption:
Step 1: How to find inverse of a with mod 26?

Example: 5 × ( Any #) modulo 26 =1, i.e. 5 × 21 modulo 26 =1

(LHS)(5 × 21 = 105 Mod(26) =1 = (RHS) 4 × 26 + 1 ≡ 105 modulo 26=1).

Step 2: We must now perform the inverse calculations on the integer


values of the ciphertext. 21(y - 8) mod (26) to get integer value again.
Practice 2
1) Encrypt and Decrypt the plaintext “world war", using the key a =
5, b = 8.

2) Encrypt and Decrypt the plaintext ”TWENTY FIFTEEN” using the key
a=17,b=20.

3) Encrypt and Decrypt the Plaintext “ITS COOL with” using the key a =
5, b = 8.
Cipher Text
1) OAPLX OIP

2) FEKHFM BABFKKH

You might also like