You are on page 1of 18

Coding Theory

and Cryptography
CODING THEORY and CRYPTOGRAPHY

introduction
• Some technological creations which are attributed to the use of codes are:
• Television sets
• Computers
• Cellular communication
• Coding theory traces its origin to the design and implementation of efficient and reliable
means of storing and transmitting data.
• It is usually associated with encryption and decryption in cryptography as well as error
correction in communication and networks.
CRYPTOGRAPHY

Learning outcomes
At the end of the section, students must be able to:
Explain the basic principles of cryptography;
Describe the different methods of data encryption and decryption; and
Demonstrate and apply the different processes of cryptography
Cryptography
Crytography is the process of converting data or information
into codes, primarily for the purpose of keeping it secured
(confidential and undistorted).
Encryption and Decryption
Encryption basically converts a message into meaningless and
usually unreadable formats that only the intended recipient can
understand.
Decryption is the process of recovering the encrypted information.
Shift Cipher Method
The shift cipher method is a substitution method and one of the oldest method of
encrypting and decrypting information. Julius Caesar used this type of cipher to
send messages to his military commanders.
Every (English) alphabet is replaced by another letter which is at some fixed
number of positions according to the natural order of the letters. This number is
called the the encryption key. It is just the length of the shift we are using.
CRYPTOGRAPHY

Shift Cipher Method


Mathematically, it is described using the formula
𝑪=(𝑶+𝑲)𝒎𝒐𝒅 𝟐𝟔
Where C is the coded letter, O the original letter, and K a constant
corresponding to the number of positions to find the coded letter C.
Example 1
Encrypt the phrase “My Password” using a shift cipher K = 7.

o make all of this more mathematical, consider the following


con ersion table for the English alphabet:

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
ABCDEFGH J K L M N O P Q S U X Y Z
Example 1
Encrypt the phrase “My Password” using a shift cipher K = 7.

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
ABCDEFGH J K L M N O P Q S U X Y Z

M=12, y=24, P=15, a=0, s=18, s=18, w=22, o=14, r=17, and d=3

We get the following: 12, 24, 15, 0, 18, 18, 22, 14, 17, 3

Add 7 to each number: 19, 31, 22, 7, 25, 25, 29, 21, 24, 10

Replace each number with the corresponding letter. For numbers


exceeding 25, we get the modulus 26 of the number, 26 being the number of
characters in our shift cipher. For example, 31 mod 26 ≡ 5. So replace 31
with the letter corresponding to 5. So we get, 19 = T, 31mod26≡5 = F, 22 = W,
7 = H, 25 = Z, 25 = Z, 29mod26≡3 = D, 21 = V, 24 = Y, and 10 = K.
Thus, My Password = TF WHZZDVYK
CRYPTOGRAPHY

Decrypting
If you are the receiver of the message the you have to decrypt the message or
return it back to its original form. It is done by using the the following
formula
Encryption formula: 𝑪 = (𝑶 + 𝑲) 𝒎𝒐𝒅 𝟐𝟔
Decryption formula: = (𝑪 − 𝑲) 𝒎𝒐𝒅 𝟐𝟔
CRYPTOGRAPHY

Example 2
Decrypt the phrase “GUNBLOFYM” using a backward shift cipher K = 20.
Using the same shift cipher

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
ABCDEFGH J K L M N O P Q S U X Y Z
G=6, U=20, N=13, B=1, L=11, O=14, F=5, Y=24, and M=12

To get the original letters of the message we need to subtract the


decrption key, k = 20. But this will lead to negative numbers which might
be difficult for some. An alternative method would be to subtract 20 from
26 which will give 6. So, instead of subtracting 20 we can add 6 to get the
numbers corresponding to the original letters of the message.
CRYPTOGRAPHY

Example 2
Decrypt the phrase “GUNBLOFYM” using a backward shift cipher K = 20.

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
ABCDEFGH J K L M N O P Q S U X Y Z

From G=6, U=20, N=13, B=1, L=11, O=14, F=5, Y=24, and M=12 we get the
following sequence of numbers: 6, 20, 13, 1, 11, 14, 5, 24, 12
Adding 6 to each number, we get: 12, 26, 19, 7, 17, 20, 11, 30, 18
We can now replace the numbers with the corresponding letters. Again, for
numbers exceeding 25, you apply mod 26 to get the applicable number. Thus,
12=M, 26mod26≡0 = A, 19=T, 7=H, 17=R, 20=U, 11=L, 30mod26≡4 = E, and 18=S
"GUNBLOFYM" = "MATHRULES" = "MATH RULES"
CRYPTOGRAPHY

Affine Cipher
Another substitution cipher method is the Affine Cipher. It is a more complicated
cipher formula which involves multiplying the cipher value of each letter of the
original message by m then adding the value k based on the encryption key (m, k).
In a way, this will be more difficult to crack than the shift cipher technique.
CRYPTOGRAPHY

Affine Cipher
Encryption Cipher (m, K):
𝑪=(𝒎𝑶+𝑲) 𝒎𝒐𝒅 𝟐𝟔
Decryption Cipher (m, K):
𝑶=𝟏/𝒎 (𝑪−𝑲) 𝒎𝒐𝒅 𝟐𝟔
Note: 𝟏/𝒎 here is the multiplicative inverse of m on mod 26.
CRYPTOGRAPHY

Example 3
Encrypt the phrase “codes” using the affine cipher (m, K) = (3, 5)
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
ABCDEFGH J K L M N O P Q S U X Y Z
We want to encrypt the message “codes” using an affine cipher with encryption key (3, 5).
1. Using the table, represent “codes” with their corresponding numbers: 2 14 3 4 18.
2. Multiply each of the numbers from step 1 by the first number in the encryption key, (3 in
this case), to get: 6 42 9 12 54.
3. Add the second number in the encryption key, (5 in this case), to each of the numbers
from step 2 to get: 11 47 14 17 59.
4. Use the table to replace the numbers from step 3 with their corresponding letters. For
numbers exceeding 25, use mod 26 to obtain the appropriate number. We get, 11=L,
47mod26≡21 = V, 14=O, 17=R, 59mod26≡7 = H.
Therefore, "codes" = "lvorh"
CRYPTOGRAPHY

Example 4
Apply the Affine Cipher using (m, k) = (5, 21) decrypt the message: MVTPVACPVT
M=12, V=21, T=19, P=15, V=21, A=0, C=2, P=15, V=21, T=19
Using the formula to decrypt Affine cipher, we need to perform the following
calculation on each integer: O = a(C - k) mod 26
where a is the modular multiplicative inverse of m. That is, a x m = 1 mod 26 (a is the
number such that when you multiply m by it, and keep taking away the length of the
alphabet, you get to 1).
Using m = 5, k = 21, the first step here is to find the inverse of a, which in this case is
21 (since 21 x 5 = 105 = 1 mod 26, as 26 x 4 = 104, and 105 - 104 = 1).
CRYPTOGRAPHY

Example 4
Apply the Affine Cipher using (m, k) = (5, 21) decrypt the message: MVTPVACPVT
We must now perform the inverse calculations on the integer values of the ciphertext,
in this case the calculation in 21(C - 21) mod 26 and finally convert the integers back
to plaintext letters. This is shown in the table below.

Ciphertext: M V T P V A C P V T
C: 12 21 19 15 21 0 2 15 21 19
21(C - 21): 357 0 504 420 0 105 147 420 0 504
Note that if you don't want to get negative numbers, instead of subtracting the value of
k = 21, you can add its additive inverse mod 26 which is 5 (number which when added
to the value of k = 26 gives a sum of 26.
21(C-21)mod26: 19 0 10 4 0 1 17 4 0 10
Plaintext: T A K E A B R E A K

Original message is "Take a break"


CODING THEORY and CRYPTOGRAPHY

THANK YOU!

You might also like