Module 8. Coding Theory and Cryptography (1)
Module 8. Coding Theory and Cryptography (1)
b. 19 ≅ 4 mod 7
19−4 15
Observe that = is not an integer. The congruence is not true.
7 7
Example 2: Evaluate (15 + 18) mod 9
Solution 1:
- First add 15 + 18 to get 33
33 6
- get the modular value of 33: =3+
9 9
So, the remainder is 6
Therefore, (15 + 18) mod 9 = 6
Equivalently, we can say (15 + 18) ≅ 6 (mod 9)
Example 2: Evaluate (15 + 18) mod 9
Solution 2:
1 ----> quotient
- get the modular values of the addends 9 ) 15
15 6 9
=1 + ➔ 15 (mod 9) = 6 -------------
9 9
18 0 6 ----> remainder
=2 + ➔ 18 (mod 9) = 0
9 9
- add the modular values
(15 + 18) mod 9 = (6 + 0) mod 9 = 6
Example 3: Evaluate (72 - 35) mod 11
Solution 1:
- First obtain the difference: 72 – 35 = 37
37 4
- get the modular value of 37: =3+
11 11
So, the remainder is 4
Therefore, (72 - 35) mod 11 = 4
Equivalently, we can say (72 - 35) ≅ 4 (mod 11)
Example 3: Evaluate (72 - 35) mod 11
Solution 2:
- First get the modular values of 72 and 35
72 6
=6+ ➔ 72 (mod 11) = 6
11 11
35 2
=3+ ➔ 35 (mod 11) = 2
11 11
- subtract the modular values : 6 – 2 =4
Therefore, (72 – 35) mod 11 = (6 – 2) mod 11 = 4 mod 11 = 4
Example 4: Evaluate (54)(27) mod 23
Solution 1:
- First multiply: (54)(27) = 1458
1458 9
- get the modular value of 1458: = 63 +
23 23
So, the remainder is 9
Therefore, (54)(27) mod 23 = 9
Equivalently, we can say (54)(27) ≅ 9 (mod 23)
Example 4: Evaluate (54)(27) mod 23
Solution 2:
- First calculate the modular values of the factors
54 8
=2 + ➔ 54 (mod 23) = 8
23 23
27 4
=1 + ➔ 27 (mod 23) = 4
23 23
- multiply the modular values: (8)(4) = 32 > 23
32 9
- get the modular value of 32: =1+ ➔ 32 (mod 23) = 9
23 23
Therefore, (54)(27) mod 23 = 32 (mod 23) = 9
Exercise: Evaluate the following
Sum = 1+0+2+6+4+1+6+2+2+3+6+4+2+0+2+2+1+8+8
= 60 ≅ 0 (mod 10)
The indicated credit card number is valid.
b. 6011 0123 9145 2317
Sum = 53 ≅ 3 (mod 10)
Not Valid
Section 8.2 Binary system and Hamming Codes
Other than the decimal system which is the most common number system, there
are other number systems that serve specific purposes. There is the octal system
(which uses the digits 0,1,2,…,7) widely employed in computer science and
aviation, the hexadecimal system (which uses 16 symbols: 0 – 9 and A – F) used in
most programming languages.
Then there is the binary system which uses the digits 0 and 1 under modulo 2
arithmetic. Modern computers and similar devices generally function under the
binary system as it best captures their on-off states.
Learning Outcomes
At the end of the section, students should be able to:
The place values this time are the powers of 2, such as units, twos,
fours, eights, and so on.
Illustration
Do you wonder what the binary number B = 1010110 is in the usual
decimal system?
Use the corresponding place values:
1010110 = 1(26) + 0(25) + 1(24) + 0(23) + 1(22) + 1(2) + 0
= 1(64) + 0(32) + 1(16) + 0(8) + 1(4) + 1(2) +0
= 64 + 16 + 4 + 2
= 86
In a more formal notation, write
(1010110)2 = (86)10 = 86
Illustration: Decimal to Binary
There is a simple way to convert a decimal number to its equivalent
binary form. This is done by successive division by 2. This is outlined in
the table below:
For purposes of
discussion, consider 5-
bit codes for the
familiar keys in a
standard computer
keyboard.
Example 16
Figure out the message in the following coded words:
01101000011010001000000000100110011000000011010 10101110
Example 16
00111011110010000000000100110000101100111001100
0001010001000001010000010000010000100101100010
01100001000001001011100010110011
Hamming Codes
Coded messages tend to be very prone to distortion when being
transmitted to available media because of the presence of some
environmental interference or unforeseen defects in the transmission
medium. Any changes that may occur in a message that may alter its
original meaning is considered an error. In the context of binary codes,
an error occurs when there is an unintentional alteration of the bits,
the “0” getting altered as “1” or the other way around.
Hamming Codes
The Hamming Code, a scheme for error-correction, was introduced by
R. W. Hamming. This scheme uses a redundant bit which is called a
parity bit (also termed check bit) which is a 1-bit that is inserted in a
given string of binary codes.
A parity bit is either ‘even’ or ‘odd’ depending on whether there is an
even or odd number of 1’s.
Forming the Hamming Code
Step 1. Insert additional bit positions
If the length of the original code is r, then add m + 1 more bit positions,
where m is the largest power of 2 that satisfies the inequality: 2m < r. The positions
(𝑃𝑖 ) of the additional bits are at the corresponding powers of 2 : i=20 = 1, 21 = 2, 22
= 4,…, 2m.
Step 2. Extract subcodes for the parity codes of each additional bit.
For P1: copy the bits at positions 1,3,5,7,… (copy 1, skip 1)
For P2: copy the bits at positions 2,3,6,7,10,11,… (copy 2,skip 2)
In general, Pk : copy k bits (starting with the kth bit) then skip k bits
Step 3. Find Pi : The value of Pi is 0 if the resulting subcode in Step 2 is of even
parity, otherwise, the value is 1.
Example 18: Find the Hamming code of 10010
10010 has 5 bits (that is, it is of length 5) ====> 𝑟 = 5
Observe: 22 = 4< 5
3
𝑚 = 2, 𝑚 + 1 = 3
2 =8>5
===> Insert 3 additional bits, at positions 20, 21, and 22 (i.e. P1, P2, P4)
===> the Hamming code has 𝑚 + 1 + 𝑟 = 3 + 5 = 8 bits
Positions 1 2 3 4 5 6 7 8
Digit P1 = ? P2 = ? 1 P4 = ? 0 0 1 0
Observe that the first bit of the original code becomes the third bit of the Hamming
code, the second bit becomes the 5th bit, and all remaining bits Moving 3 bits forward.
Example 18: Find the Hamming code of 10010
111101000001010111101000101101
What is the message? Do you think there is an error? If there is, can
you correct it and get the real message?
Exercise: 111101000001010111101000101101
• Mark all bit positions that are powers of 2
111101000001010111101000101101
• original message
1010000101011101000101101
10100 00101 01110 10001 01101
T E N Q M
Exercise: 111101000001010111101000101101
P1 subcode: 110000001110110 ==> error!
P2 subcode: 111000101100011 ==> correct
P4 subcode: 101010100100101 ==> error!
P8 subcode: 000010100101101 ==> correct
P16 subcode: 111101000101101 ==> error!
With the advent of wireless communication and the widespread reliance on the
internet, information is at a high risk of being breached. Mathematics has
developed a system by which this problem can be addressed—through
cryptography.
Learning Outcomes
At the end of the section, students should be able to:
1. explain the basic principles of cryptography;
2. describe the different methods of data encryption and
decryption; and
3. demonstrate and apply the different processes of
cryptography.
Definitions
Cryptography is the process of converting data or information into
codes, primarily for the purpose of keeping it secured (confidential
and undistorted). It involves encryption and decryption. Encryption
basically converts a message into meaningless and usually unreadable
formats that only the intended recipient can understand. Decryption,
on the other hand, is the process of recovering the encrypted
information.
Shift Cipher
Formula: 𝐶 = 𝑃 + 𝐾 𝑚𝑜𝑑 26
𝑃 is the original position of a letter in the given message, 𝐶 is
the shifted position (code letter), 𝐾 is a constant that
determines the fixed number of shift positions.
Example 1: Encryption
Original position 11 4 19 20 18 3 17 8 13 10 2 14 5 5 4 4
Shifted position 20 13 2 3 1 12 0 17 22 19 11 23 14 14 13 13
Code letter U N C D B M A R W T L X O O N N
Position(C) 17 5 9 22 2 2 23 5 9 2 11 16 21 23 4 17 13
Original position
8 22 0 13 19 19 14 22 0 19 2 7 12 12 21 8 4
(P)
Original letter I W A N T T O W A T C H M O V I E
Original position 11 4 19 20 18 3 17 8 13 10 2 14 5 5 4 4
New position 12 17 10 13 7 14 4 3 18 9 11 21 20 20 17 17
Code letter M R K N H O E D S J L V U U R R
Position(C) 3 19 5 18 10 10 21 19 5 10 11 0 15 21 16 3 17
Original position
8 22 0 13 19 19 14 22 0 19 2 7 12 14 21 8 4
(P)
Original letter I W A N T T O W A T C H M O V I E