ENCODING and DECODING
Math 1
Mathematics for General Education
Institute of Mathematics University of the Philippines Diliman
Modular Systems
Recall:
congruence modulo 12 (≡
12)
a ≡
12b ⇐⇒ (a − b) is divisible by 12
⇐⇒ a and b have the same remainder when divided by 12
Modulo 12 Addition ⊕
12a ⊕
12b = (a + b) mod 12
Modulo 12 Multiplication
12a
12b = (a · b) mod 12
Modular Systems
Recall:
congruence modulo 12 (≡
12)
a ≡
12b ⇐⇒ (a − b) is divisible by 12
⇐⇒ a and b have the same remainder when divided by 12
Modulo 12 Addition ⊕
12a ⊕
12b = (a + b) mod 12
Modulo 12 Multiplication
12a
12b = (a · b) mod 12
Modular Systems
Recall:
congruence modulo 12 (≡
12)
a ≡
12b ⇐⇒ (a − b) is divisible by 12
⇐⇒ a and b have the same remainder when divided by 12
Modulo 12 Addition ⊕
12a ⊕
12b = (a + b) mod 12
Modulo 12 Multiplication
12a
12b = (a · b) mod 12
Modular Systems
Recall:
congruence modulo 12 (≡
12)
a ≡
12b ⇐⇒ (a − b) is divisible by 12
⇐⇒ a and b have the same remainder when divided by 12
Modulo 12 Addition ⊕
12a ⊕
12b = (a + b) mod 12
Modulo 12 Multiplication
12a
12b = (a · b) mod 12
Modular Systems
Recall:
congruence modulo 12 (≡
12)
a ≡
12b ⇐⇒ (a − b) is divisible by 12
⇐⇒ a and b have the same remainder when divided by 12
Modulo 12 Addition ⊕
12a ⊕
12b = (a + b) mod 12
Modulo 12 Multiplication
12a
12b = (a · b) mod 12
Modular Systems
Recall:
congruence modulo 12 (≡
12)
a ≡
12b ⇐⇒ (a − b) is divisible by 12
⇐⇒ a and b have the same remainder when divided by 12
Modulo 12 Addition ⊕
12a ⊕
12b = (a + b) mod 12
Modular Systems
congruence modulo n (≡
n)
a ≡
nb ⇐⇒ (a − b) is divisible by n
⇐⇒ a and b have the same remainder when divided by n
Modulo n Addition ⊕
na ⊕
nb = (a + b) mod n
Modulo n Multiplication
na
nb = (a · b) mod n
Modular Systems
congruence modulo n (≡
n)
a ≡
nb ⇐⇒ (a − b) is divisible by n
⇐⇒ a and b have the same remainder when divided by n
Modulo n Addition ⊕
na ⊕
nb = (a + b) mod n
Modulo n Multiplication
na
nb = (a · b) mod n
Modular Systems
congruence modulo n (≡
n)
a ≡
nb ⇐⇒ (a − b) is divisible by n
⇐⇒ a and b have the same remainder when divided by n
Modulo n Addition ⊕
na ⊕
nb = (a + b) mod n
Modulo n Multiplication
na
nb = (a · b) mod n
Modular Systems
congruence modulo n (≡
n)
a ≡
nb ⇐⇒ (a − b) is divisible by n
⇐⇒ a and b have the same remainder when divided by n
Modulo n Addition ⊕
na ⊕
nb = (a + b) mod n
Modulo n Multiplication
na
nb = (a · b) mod n
Modular Systems
congruence modulo n (≡
n)
a ≡
nb ⇐⇒ (a − b) is divisible by n
⇐⇒ a and b have the same remainder when divided by n
Modulo n Addition ⊕
na ⊕
nb = (a + b) mod n
Modulo 2
a ≡
2b ⇐⇒ (a − b) is divisible by 2
⇐⇒ a and b have the same remainder when divided by 2
The only possible remainders when we divide an integer by 2 are 0
and 1.
Modulo 2
a ≡
2b ⇐⇒ (a − b) is divisible by 2
⇐⇒ a and b have the same remainder when divided by 2
The only possible remainders when we divide an integer by 2 are 0
and 1.
Modulo 2
a ≡
2b ⇐⇒ (a − b) is divisible by 2
⇐⇒ a and b have the same remainder when divided by 2
The only possible remainders when we divide an integer by 2 are 0
and 1.
Modulo 2
a ≡
2b ⇐⇒ (a − b) is divisible by 2
⇐⇒ a and b have the same remainder when divided by 2
The only possible remainders when we divide an integer by 2 are 0
and 1.
Modulo 2
Example 4 ≡
22 7 ≡
23 2 6≡ 5
We let
Z
2= {0, 1}. Note:
0 represents all even integers
1 represents all odd integers
Modulo 2
Example 4 ≡
22 7 ≡
23 2 6≡ 5 We let
Z
2= {0, 1}.
Note:
0 represents all even integers
1 represents all odd integers
Modulo 2
Example 4 ≡
22 7 ≡
23 2 6≡ 5 We let
Z
2= {0, 1}.
Note:
0 represents all even integers
1 represents all odd integers
Addition and Multiplication Modulo 2
Addition and Multiplication Modulo 3
Z
3= {0, 1, 2}
Note that the possible remainders when we divide a whole number by
3 are 0, 1, and 2.
Addition and Multiplication Modulo 3
Z
3= {0, 1, 2}
Note that the possible remainders when we divide a whole number by
3 are 0, 1, and 2.
Addition and Multiplication Modulo 3
Z
3= {0, 1, 2}
Note that the possible remainders when we divide a whole number by
3 are 0, 1, and 2.
Addition and Multiplication Modulo 4
Z
4= {0, 1, 2, 3}
Addition and Multiplication Modulo 4
Z
4= {0, 1, 2, 3}
Addition and Multiplication Modulo 5
Z
5= {0, 1, 2, 3, 4}
Addition and Multiplication Modulo 5
Z
5= {0, 1, 2, 3, 4}
Consider Z
26= {0, 1, · · · , 24, 25}.
Assign to each letter an element of Z
26.
Encode: MATH
ENCODING FORMULA: y = x ⊕ 10
M = 13
A = 1
T = 20
H = 8
Encode: MATH
ENCODING FORMULA: y = x ⊕ 10
M = 13
A = 1
T = 20
H = 8
Encode: MATH
ENCODING FORMULA: y = x ⊕ 10
To encode M: Let x = 13.
=⇒ y = 13 ⊕ 10 = 23 = W To encode A: Let x = 1.
=⇒ y = 1 ⊕ 10 = 11 = K To encode T: Let x = 20.
=⇒ 20 ⊕ 10 = 30 ≡
264 = D To encode H: Let x = 8.
=⇒ y = 8 ⊕ 10 = 18 = R
Encode: MATH
ENCODING FORMULA: y = x ⊕ 10 To encode M: Let x = 13.
=⇒ y = 13 ⊕ 10 = 23 =
W
To encode A: Let x = 1.
=⇒ y = 1 ⊕ 10 = 11 = K To encode T: Let x = 20.
=⇒ 20 ⊕ 10 = 30 ≡
264 = D To encode H: Let x = 8.
=⇒ y = 8 ⊕ 10 = 18 = R
Encode: MATH
ENCODING FORMULA: y = x ⊕ 10 To encode M: Let x = 13.
=⇒ y = 13 ⊕ 10 = 23 = W
To encode A: Let x = 1.
=⇒ y = 1 ⊕ 10 = 11 = K To encode T: Let x = 20.
=⇒ 20 ⊕ 10 = 30 ≡
264 = D To encode H: Let x = 8.
=⇒ y = 8 ⊕ 10 = 18 = R
Encode: MATH
ENCODING FORMULA: y = x ⊕ 10 To encode M: Let x = 13.
=⇒ y = 13 ⊕ 10 = 23 = W To encode A: Let x = 1.
=⇒ y = 1 ⊕ 10 = 11 =
K
To encode T: Let x = 20.
=⇒ 20 ⊕ 10 = 30 ≡
264 = D To encode H: Let x = 8.
=⇒ y = 8 ⊕ 10 = 18 = R
Encode: MATH
ENCODING FORMULA: y = x ⊕ 10 To encode M: Let x = 13.
=⇒ y = 13 ⊕ 10 = 23 = W To encode A: Let x = 1.
=⇒ y = 1 ⊕ 10 = 11 = K
To encode T: Let x = 20.
=⇒ 20 ⊕ 10 = 30 ≡
264 = D To encode H: Let x = 8.
=⇒ y = 8 ⊕ 10 = 18 = R
Encode: MATH
ENCODING FORMULA: y = x ⊕ 10 To encode M: Let x = 13.
=⇒ y = 13 ⊕ 10 = 23 = W To encode A: Let x = 1.
=⇒ y = 1 ⊕ 10 = 11 = K To encode T: Let x = 20.
=⇒ 20 ⊕ 10 = 30 ≡
264 = D To encode H: Let x = 8.
=⇒ y = 8 ⊕ 10 = 18 = R
Encode: MATH
ENCODING FORMULA: y = x ⊕ 10 To encode M: Let x = 13.
=⇒ y = 13 ⊕ 10 = 23 = W To encode A: Let x = 1.
=⇒ y = 1 ⊕ 10 = 11 = K To encode T: Let x = 20.
=⇒ 20 ⊕ 10 = 30 ≡
264 =
D To encode H: Let x = 8.
=⇒ y = 8 ⊕ 10 = 18 = R
Encode: MATH
ENCODING FORMULA: y = x ⊕ 10 To encode M: Let x = 13.
=⇒ y = 13 ⊕ 10 = 23 = W To encode A: Let x = 1.
=⇒ y = 1 ⊕ 10 = 11 = K To encode T: Let x = 20.
=⇒ 20 ⊕ 10 = 30 ≡
264 = D
To encode H: Let x = 8.
=⇒ y = 8 ⊕ 10 = 18 = R
Encode: MATH
ENCODING FORMULA: y = x ⊕ 10 To encode M: Let x = 13.
=⇒ y = 13 ⊕ 10 = 23 = W To encode A: Let x = 1.
=⇒ y = 1 ⊕ 10 = 11 = K To encode T: Let x = 20.
=⇒ 20 ⊕ 10 = 30 ≡
264 = D To encode H: Let x = 8.
R
Encode: MATH
ENCODING FORMULA: y = x ⊕ 10 To encode M: Let x = 13.
=⇒ y = 13 ⊕ 10 = 23 = W To encode A: Let x = 1.
=⇒ y = 1 ⊕ 10 = 11 = K To encode T: Let x = 20.
=⇒ 20 ⊕ 10 = 30 ≡
264 = D
To encode H: Let x = 8.
Encoding Formula: y = x ⊕ 10
Table:Encoding
Encode M A T H
x 13 1 20 8
y 23 11 4 18
Encoded W K D R
Decode: WKDR
W= 23 K= 11 D= 4 R= 18
To obtain DECODING FORMULA:
Encoding Formula: y = x ⊕ 10
=⇒ y ⊕ 16 = x ⊕ 10 ⊕ 16
=⇒ y ⊕ 16 = x DECODING FORMULA: x = y ⊕ 16.
W: 23 ⊕ 16 = 39 ≡
2613 =M K: 11 ⊕ 16 = 27 ≡
261 =A D: 4 ⊕ 16 = 20 =T
R: 18 ⊕ 16 = 34 ≡
268 =H
Decode: WKDR
W= 23 K= 11 D= 4 R= 18
To obtain DECODING FORMULA:
Encoding Formula: y = x ⊕ 10
=⇒ y ⊕ 16 = x ⊕ 10 ⊕ 16
=⇒ y ⊕ 16 = x
DECODING FORMULA: x = y ⊕ 16. W: 23 ⊕ 16 = 39 ≡
2613 =M K: 11 ⊕ 16 = 27 ≡
261 =A D: 4 ⊕ 16 = 20 =T
R: 18 ⊕ 16 = 34 ≡
268 =H
Decode: WKDR
W= 23 K= 11 D= 4 R= 18
To obtain DECODING FORMULA:
Encoding Formula: y = x ⊕ 10
=⇒ y ⊕ 16 = x ⊕ 10 ⊕ 16
=⇒ y ⊕ 16 = x DECODING FORMULA: x = y ⊕ 16.
W: 23 ⊕ 16 = 39 ≡
2613 =
M K: 11 ⊕ 16 = 27 ≡
261 =A D: 4 ⊕ 16 = 20 =T
R: 18 ⊕ 16 = 34 ≡
268 =H
Decode: WKDR
W= 23 K= 11 D= 4 R= 18
To obtain DECODING FORMULA:
Encoding Formula: y = x ⊕ 10
=⇒ y ⊕ 16 = x ⊕ 10 ⊕ 16
=⇒ y ⊕ 16 = x DECODING FORMULA: x = y ⊕ 16.
W: 23 ⊕ 16 = 39 ≡
2613 =M
K: 11 ⊕ 16 = 27 ≡
261 =A D: 4 ⊕ 16 = 20 =T
R: 18 ⊕ 16 = 34 ≡
268 =H
Decode: WKDR
W= 23 K= 11 D= 4 R= 18
To obtain DECODING FORMULA:
Encoding Formula: y = x ⊕ 10
=⇒ y ⊕ 16 = x ⊕ 10 ⊕ 16
=⇒ y ⊕ 16 = x DECODING FORMULA: x = y ⊕ 16.
W: 23 ⊕ 16 = 39 ≡
2613 =M K: 11 ⊕ 16 = 27 ≡
261 =
A D: 4 ⊕ 16 = 20 =T
R: 18 ⊕ 16 = 34 ≡
268 =H
Decode: WKDR
W= 23 K= 11 D= 4 R= 18
To obtain DECODING FORMULA:
Encoding Formula: y = x ⊕ 10
=⇒ y ⊕ 16 = x ⊕ 10 ⊕ 16
=⇒ y ⊕ 16 = x DECODING FORMULA: x = y ⊕ 16.
W: 23 ⊕ 16 = 39 ≡
2613 =M K: 11 ⊕ 16 = 27 ≡
261 =A
D: 4 ⊕ 16 = 20 =T
R: 18 ⊕ 16 = 34 ≡
268 =H
Decode: WKDR
W= 23 K= 11 D= 4 R= 18
To obtain DECODING FORMULA:
Encoding Formula: y = x ⊕ 10
=⇒ y ⊕ 16 = x ⊕ 10 ⊕ 16
=⇒ y ⊕ 16 = x DECODING FORMULA: x = y ⊕ 16.
W: 23 ⊕ 16 = 39 ≡
2613 =M K: 11 ⊕ 16 = 27 ≡
261 =A
T
R: 18 ⊕ 16 = 34 ≡
268 =H
Decode: WKDR
W= 23 K= 11 D= 4 R= 18
To obtain DECODING FORMULA:
Encoding Formula: y = x ⊕ 10
=⇒ y ⊕ 16 = x ⊕ 10 ⊕ 16
=⇒ y ⊕ 16 = x DECODING FORMULA: x = y ⊕ 16.
W: 23 ⊕ 16 = 39 ≡
2613 =M K: 11 ⊕ 16 = 27 ≡
261 =A
R: 18 ⊕ 16 = 34 ≡
268 =H
Decode: WKDR
W= 23 K= 11 D= 4 R= 18
To obtain DECODING FORMULA:
Encoding Formula: y = x ⊕ 10
=⇒ y ⊕ 16 = x ⊕ 10 ⊕ 16
=⇒ y ⊕ 16 = x DECODING FORMULA: x = y ⊕ 16.
W: 23 ⊕ 16 = 39 ≡
2613 =M K: 11 ⊕ 16 = 27 ≡
261 =A
H
Decode: WKDR
W= 23 K= 11 D= 4 R= 18
To obtain DECODING FORMULA:
Encoding Formula: y = x ⊕ 10
=⇒ y ⊕ 16 = x ⊕ 10 ⊕ 16
=⇒ y ⊕ 16 = x DECODING FORMULA: x = y ⊕ 16.
W: 23 ⊕ 16 = 39 ≡
2613 =M
K: 11 ⊕ 16 = 27 ≡
261 =A
Decoding Formula: x = x ⊕ 16
Table: Decoding
Decode W K D R
y 23 11 4 18
x 13 1 20 8
Encoded M A T H
Exercise:
Encoding Formula: y = x ⊕ 20
1
Encode: LOVE
2
Find the Decoding Formula.
3