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

Module 8

Coding Theory
and
Cryptography
At the end of the period, the students should be able to

1. Use coding schemes to encode and decode different types of


information for identification, privacy, and security purposes.
2. Exemplify honesty and integrity when using codes for security
purposes.
1. Binary System

Binary System is a special system used particularly in


computer science and logic designs which uses 1s and 0s, it is
also called the based 2 number system.

26 = 64 25 = 32 24 = 16 23 = 8 22 = 4 21 = 2 20 = 1
eights fours twos ones
Converting Decimal Number to Binary Number
Solution A. Base 2 Method
26 = 64 25 = 32 24 = 16 23 = 8 22 = 4 21 = 2 20 = 1

Example: Convert 9, 25, and 97 into binary number.

Step 1: Choose a base 2 number in the binary number system that is less than or equal
to 9. Make it sure that each group must have 4 members. That is,
23 = 8 22 = 4 21 = 2 20 = 1

Step 2: Add the numbers that will be equal to 9. That is,


23 = 8 + 20 = 1
Step 3: Those base 2 number in step 2 will be labeled as 1. Then, the rest will be
labeled 0. Therefore, 9 = 1001
Converting Decimal Number to Binary Number
Solution B. Division and Remainder Method

- Divide the given decimal number into 2 and determine if there is a remainder. If there is no
remainder, put “0” and if there is, put “1”

Example: Convert 25 to a binary number

Decimal number/2 New Decimal Remainder


25/2 12 1
12/2 6 0
6/2 3 0
3/2 1 1
1/2 0 1

Therefore, 25 = 11001
Converting Binary Number to Decimal Number

B  an 2n  an 1 2n 1  an  2 2n  2  ......  a0

Example: Convert 1010110 to Decimal Number

Solution.

1x26 + 0x25 + 1x24 + 0x23 +1x22 + 1x21 +0x20 = 64+0+16+0+4+2+0 = 86


Character Decimal Character Decimal Character Decimal Character Decimal
0 48 9 57 I 73 R 82
1 49 A 65 J 74 S 83
2 50 B 66 K 75 T 84
3 51 C 67 L 76 U 85
4 52 D 68 M 77 V 86
5 53 E 69 N 78 W 87
6 54 F 70 O 79 X 88
7 55 G 71 P 80 Y 89
8 56 H 72 Q 81 Z 90
Character Decimal Character Decimal Character Decimal Character Decimal
a 97 j 106 s 115 + 43
b 98 k 107 t 116 ? 63
c 99 l 108 u 117 ! 33
d 100 m 109 v 118 $ 36
e 101 n 110 w 119 % 37
f 102 o 111 x 120 & 38
g 103 p 112 y 121 * 42
h 104 q 113 z 122 ( 40
i 105 r 114 = 61 ) 41
Encoding of Message Using Binary Codes

Example: Code the message “LOVE GOD” using the binary code.

Letter L O V E G O D
Decimal 76 79 86 69 71 79 68
Binary 01001100 01001111 01010110 01000101 01000111 01001111 01000100

Step 1. L = 76, 27 = 128 26 = 64 25 = 32 24 = 16 23 = 8 22 = 4 21 = 2 20 = 1

Step 2. 26 = 64 + 23 = 8 + 22 = 4

Step 3. 01001100
01001100010011110101011001000101010001110100111101000100
Decoding of Message Using Binary Codes

Example: Decode the message


01001100010011110101011001000101010001110100111101000100

Binary Code Decimal Number Message


01001100 76 L
01001111 79 O
01010110 86 V
Solution:
01000101
Segregate the69codes by blocks of 5 bits
E
01000111 71 G
01001111 79 O
01000100 68 D
Exercise:

1. Convert the following into Binary Number


a. 134 b. 98 c. 231

2. Convert the following into Decimal Number


a. 11001110 b. 001101110110 c. 11011001

3. Encode the message “ChoOsE 2 Be HaPpy” following the ASCII

4. Make a message that contains 3 words. Use the binary equivalent of the
letters in encoding or decoding the message.

You might also like