Coding
Coding
CODES
COMMUNICATION
SECURITY
▷ When a personal message is sent, or a company secret is transmitted,
you do not want that message to leak to other people other than the one
intended.
3
Shift Cipher
▷ One of the earliest known cipher is the Shift Cipher. It is done by shifting each of
the true letters of the message n alphabetical characters to the right. Hence, the
resulting message is a sentence that may not be readable at all. Caesar Cipher is
attributed to Emperor Julius Caesar. During his time, he sends a message by
shifting each of the true letters of the message 3 alphabetical characters to the
right.
▷ Shift: 3
4
Example
▷ Encrypt the message, “I Love Math” using Caesar Cipher, shift 3.
I L M
O A
V T
E H
Result: 5
Example
▷ Decrypt the message, “L ORYH PDWK” using Caesar Cipher, shift 3.
L O P
R D
Y W
Result: H K
6
Example
▷ Encrypt the message, “I am Worthy” using Shift Cipher, shift 5.
Shift: 5
I W
O
A R
M T
H
Y
Result: 7
Example
▷ Encrypt the message, “I am Worthy” using Shift Cipher, shift 5.
Shift: 5
I N W B H M
O R Y D
A F R W
M R T Y
Result: N FR BRWYMD 8
Affine Cipher
▷ Affine cipher uses the numeric value of the alphabet. Hence, we have
the table,
9
Steps
1. Look for the numeric value of the letter. Let the numeric value be x.
2. Choose a number less than 26 and relatively prime to it. Let this
number be a. The only numbers that are less than 26 and relatively
prime to it are 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25.
3. Assign the shift value. Let this number be b.
4. Use the formula, y ≡ (ax + b)mod 26.
10
Example
▷ Encrypt the message, “Home” using affine cipher with a=3, and b=2.
Numeric values: H = 7, O = 14, M = 12, E = 4
Let a=3, b=2
Using the formula y ≡ (ax + b)mod 26,
For H, x=7,
y ≡ (ax + b)mod 26
y ≡ (3(7) + 2)mod 26
y ≡ (21 + 2)mod 26
y ≡ 23 mod 26
y = 23
y = X.
Hence, H will be written as X. 11
For O, x=14. For M, x=12.
y ≡ (ax + b) mod 26 y ≡ (ax + b)mod 26
y ≡ (3(14) + 2) mod 26 y ≡ (3(12) + 2)mod 26
y ≡ (42 + 2) mod 26 y ≡ (36 + 2)mod 26
y ≡ 44 mod 26 44-26=18 y ≡ 38 mod 26
y = 18 y = 12
y = S. y = M.
Hence, O will be written as S. Hence, M will be written as M.
12
For E, x=4.
y ≡ (ax + b)mod 26
y ≡ (3(4) + 2)mod 26
y ≡ (12 + 2)mod 26
y ≡ 14mod 26
y = 14
y = O.
Hence, E will be written as O.
13
Vigenere Cipher
▷ The Vigenere Cipher uses a tabula recta or Vigenere square, or Vigenere
table. It is a 26x26 matrix of the English Alphabet. The first row
consists of a sequence of letters from A to Z, followed by another
sequence of letters now from B to Z, with A in its last. Then, C to B, D
to C, and so on.
▷ To use the Vigenere Cipher, you a message to be encrypted, and a
keyword.
14
15
Example
▷ Encrypt the message, “Math” using the keyword “Easy”.
16
M
A
T
H
17
Example
▷ Decrypt the message, “Qalf” using the keyword “Easy”.
18
Q
A
L
F
19
Example
▷ Encrypt the message “Faith” using the keyword “Life”.
F
A
I
T
H
20
F Q
A I
I N
T X
H S
21