0% found this document useful (0 votes)
117 views

Chapter 6.1 Coding and Cryptography (Modular Arithmetic and Congruence)

10 + 2 + 6 + 4 + 16 + 2 + 2 + 3 + 6 + 4 + 2 + 0 + 2 + 2 + 18 + 8 = 87 87 mod 10 = 7 ≠ 0 The credit card number 5234 8213 3410 1298 is NOT VALID. b. 4539 2587 3456 3214 Digit 4 5 3 9 2 5 8 7 3 4 5 6 3 2 1 4 8 10 6 9 4 10 16 7 6 4 10 12 6 4 2 8 10 + 10 + 6 + 9 + 4

Uploaded by

Kyle Martinez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views

Chapter 6.1 Coding and Cryptography (Modular Arithmetic and Congruence)

10 + 2 + 6 + 4 + 16 + 2 + 2 + 3 + 6 + 4 + 2 + 0 + 2 + 2 + 18 + 8 = 87 87 mod 10 = 7 ≠ 0 The credit card number 5234 8213 3410 1298 is NOT VALID. b. 4539 2587 3456 3214 Digit 4 5 3 9 2 5 8 7 3 4 5 6 3 2 1 4 8 10 6 9 4 10 16 7 6 4 10 12 6 4 2 8 10 + 10 + 6 + 9 + 4

Uploaded by

Kyle Martinez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

CODING THEORY AND CRYPTOGRAPHY

Prepared by: Mrs. Carizza Batac-Almodiel GCC College Faculty [email protected]


OBJECTIVES:
At the end of the section,
students should be able to:
§ explain modular arithmetic;
§ perform modular arithmetic;
and
§ apply modular arithmetic in
real-life situations.
INSTRUCTIONS: Provide the answer as required.

1. If today is Tuesday, what day


will it be 15 days from now?
2. Will the year 2100 be a leap
year?
3. In a 12-hour clock, what time
is 45 hours before 2 o’clock?
4. How many digits constitute
an International Standard
Book Number (ISBN)?
5. Is 6011 0123 9145 2317 a
valid credit card number?
CODING AND CRYPTOGRAPHY
§ The present technology is largely attributed to codes.
Examples:
§ images and sounds seen in our television
§ cellular communication using phones
§ data transmission
§ networks
§ information theory
§ computer science
§ Many real-world occurrences
operate in an unusually cyclical
process.

EXAMPLE:
ü Earth’s rotation around the sun,
24-hour clock cycle
ü 7 days a week
ü 60 minutes per hour

NOTE:
15 hours added to 18 hours does
not count 33 hours on the clock but
rather 9 hours.
§ Consider two integers x and y and a
natural number n. You can say that
“x and y are congruent modulo n”
(or “x is congruent to y modulo n”) if
the difference of x-y is exactly
divisible by n.
§ The symbol “ ≅ ” is used to denote
congruence.
§ The natural number n is commonly
termed as the modulus of the
congruence 𝒙 ≅ 𝒚.
§ In symbols, 𝒙 ≅ 𝒚 𝒎𝒐𝒅𝒖𝒍𝒐 𝒏
𝒙"𝒚
whenever is an integer.
𝒏
§ The modular value is the remainder
when a given number is divided by
the modulus.
§ The modular value should be less
than the modulus.
Example 1:
Verify the following congruence:

1. 27 ≅ 2 mod 5

2. 19 ≅ 4 mod 7
Example 2:
Evaluate the following operations.

1. 15 + 18 mod 9
2. 72 − 35 mod 11
3. 13 22 mod 6
4. 54 27 mod 23
Example 2:
Evaluate the following operations.
1. 15 + 18 mod 9

Solution:
15 + 18 = 33 = 9(3) + 6 (remainder)
𝟏𝟓 + 𝟖 𝐦𝐨𝐝 𝟗 ≅ 𝟔
OR
15 mod 9 ≅ 6 and 18 mod 9 ≅ 0
15 + 18 mod 9
≅ 15 mod 9 + 18 mod 9
≅ 6 + 0 mod 9 ≅ 6
𝟏𝟓 + 𝟖 𝐦𝐨𝐝 𝟗 ≅ 𝟔
Example 2:
Evaluate the following operations.
2. 72 − 35 𝑚𝑜𝑑 11

Solution:
72 - 35 = 37 = (11)(3) + 4 (remainder)
𝟕𝟐 − 𝟑𝟓 𝒎𝒐𝒅 𝟏𝟏 ≅ 𝟒
OR
72 𝑚𝑜𝑑 11 ≅ 6 and 35 𝑚𝑜𝑑 11 ≅ 2
72 − 35 𝑚𝑜𝑑 11
≅ 72 𝑚𝑜𝑑 11 − 35 𝑚𝑜𝑑 11
≅ 6 − 2 𝑚𝑜𝑑 11 ≅ 4
𝟕𝟐 − 𝟑𝟓 𝒎𝒐𝒅 𝟏𝟏 ≅ 𝟒
Example 2:
Evaluate the following operations.
3. 13 22 mod 6

Solution:
(13)(22) = 286 = (6)(47) + 4 (remainder)
𝟏𝟑)(𝟐𝟐 𝐦𝐨𝐝 𝟔 ≅ 𝟒
OR
13 mod 6 ≅ 1 and 22 mod 6 ≅ 4
13)(22 mod 6
≅ (13 mod 6)(22 mod 6)
≅ (1) 4 mod 6 ≅ 4
𝟏𝟑)(𝟐𝟐 𝐦𝐨𝐝 𝟔 ≅ 𝟒
Example 2:
Evaluate the following operations.
4. 54 27 mod 23

Solution:
(54)(27) = 1458 = (23)(63) + 9 (remainder)
𝟓𝟒)(𝟐𝟕 𝐦𝐨𝐝 𝟐𝟑 ≅ 𝟗
OR
54 mod 23 ≅ 8 and 27 mod 23 ≅ 4
54)(27 mod 23
≅ 54 mod 23 27 mod 23
≅ 8 4 mod 23 ≅ 32 mod 23 ≅ 9
𝟓𝟒)(𝟐𝟕 𝐦𝐨𝐝 𝟐𝟑 ≅ 𝟗
§ Additive Identity Element (0)
𝑟+0=0+𝑟 =𝑟

§ Multiplicative identity element (1)


𝑟M1=1M𝑟 =𝑟

§ Additive Inverse (-r)


𝑟 + −𝑟 = −𝑟 + 𝑟 = 0

!
§ Multiplicative Inverse "
1 1
𝑟 = 𝑟 =1
𝑟 𝑟
§ For each integer m, an integer b is its
additive inverse modulo n if:
𝐦 + 𝐛 = 𝟎 𝐦𝐨𝐝 𝐧
§ Similarly, for each integer m, b is its
multiplicative inverse if:
𝐦 𝐛 = 𝟏 𝐦𝐨𝐝 𝐧

***It must be emphasized that in the case of


modular multiplication, the multiplicative
inverse of an integer a exists only under
modulo n if and only if a and n are relatively
prime (they have no common factors).
Example 3 :
Determine the value of the following:

1. Additive inverse of 9 mod 15 6


2. Additive inverse of 15 mod 12 9
3. Multiplicative inverse of 3 mod 5 2
4. Multiplicative inverse of 7 mod 13 2
5. Multiplicative inverse of 4 mod 12
Multiplicative inverse of 4 mod 12
does not exist because 4 and 12 are
not relatively prime.
Example 4 :
In a 12-hour clock, determine the time:

1. 5 hours after 11 o’clock


5 + 11 = 16 ≅ 4 mod 12 (4 o’clock)
2. 65 hours after 8 o’clock
65 + 8 = 73 ≅ 1 mod 12 (1 o’clock)
3. 15 hours before 5 o’clock
5 − 15 = −10 ≅ 2 mod 12 (2 o’clock)
4. 25 hours before 10 o’clock
10 − 25 = −15 = 9 mod 12 (9 o’clock)
Example 5 :
Apply modular arithmetic to answer the
following:

1. What day of the week is 25 days


from now if today is a Monday?
25 ≅ 4 mod 7 (Friday)
Example 5 :
Apply modular arithmetic to answer the
following:
2. What day of the week is August 21 in 2019
if it fell on a Saturday in 1993?
• (1993) August 22 to December 31 (132 days)
• (2019) January 1 to August 21 (233 days)
• Leap years – 1996, 2000, 2004, 2008, 2012,
2016 (366 days each)
• All the remaining years (365 days each)
• August 22,1993 – August 21, 2019 (9496
days)
9496 ≅ 4 mod 7 (Wednesday)
Example 5 :
Apply modular arithmetic to answer the
following:
3. Connie celebrated her 12th birthday on
February 25, 2018, a Sunday. What day of
the week was she born?
• She was born February 25, 2006.
• There are 4383 days covered in the 12-year
period.
−4383 ≅ −1 mod 7 ≅ 6 mod 7
• Either you move 1 day backward or 6 days
forward, the answer will be Saturday.
• February 25, 2006 fell on a Saturday.
INTERNATIONAL STANDARD BOOK NUMBER
(ISBN)

§ ISBN was introduced as a scheme of


regulating and keeping track of various
publications in different parts of the world.
§ From a 10-digit code, it was expanded in
2007 to a 13-digit code.
§ Each published book, including media
variations---electronic, paperback,
hardcover---is assigned a distinctive ISBN
code.
INTERNATIONAL STANDARD BOOK NUMBER (ISBN)

§ In the Philippines, NLP (National Library of the


Philippines) takes charge of the ISBN registration,
allocation, and designation for Filipino publishers
and authors.

§ An ISBN code takes the form of:

𝒙𝟏 𝒙𝟐 𝒙𝟑 − 𝒙𝟒 𝒙𝟓 𝒙𝟔 − 𝒙𝟕 𝒙𝟖 − 𝒙𝟗 𝒙𝟏𝟎 𝒙𝟏𝟏 𝒙𝟏𝟐 − 𝒙𝟏𝟑


INTERNATIONAL STANDARD BOOK NUMBER
(ISBN)

• 𝑥!𝑥-𝑥. = 978 or 979


• The fourth digit 𝒙𝟒 is allocated for the
country code.
• The remaining digits, except the last, are
used to identify the author and the title of
the book.
• The last digit 𝒙𝟏𝟑 is called the check digit.
Formula for the Check Digit:
𝒙𝟏𝟑 = 𝟏𝟎 − 𝒙𝟏 + 𝟑𝒙𝟐 + 𝒙𝟑 + 𝟑𝒙𝟒 + 𝒙𝟓 + 𝟑𝒙𝟔 + 𝒙𝟕 + 𝟑𝒙𝟖 + 𝒙𝟗 + 𝟑𝒙𝟏𝟎 + 𝒙𝟏𝟏 + 𝟑𝒙𝟏𝟐 𝐦𝐨𝐝 𝟏𝟎
INTERNATIONAL STANDARD BOOK NUMBER (ISBN)
Example 6:
a. Determine the check digit for the book “Larry Can’t Cook”:978-971-27-
2769-?
𝒙𝟏𝟑 = 𝟏𝟎 − 𝒙𝟏 + 𝟑𝒙𝟐 + 𝒙𝟑 + 𝟑𝒙𝟒 + 𝒙𝟓 + 𝟑𝒙𝟔 + 𝒙𝟕 + 𝟑𝒙𝟖 + 𝒙𝟗 + 𝟑𝒙𝟏𝟎 + 𝒙𝟏𝟏 + 𝟑𝒙𝟏𝟐 𝐦𝐨𝐝 𝟏𝟎

𝑥!. = 10 − 9 + 3 7 + 8 + 3 9 + 7 + 3 1 + 2 + 3 7 + 2 + 3 7 + 6 + 3 9 mod 10
𝑥!. = 10 − 154 mod 10
𝑥!. = 10 − 4
𝒙𝟏𝟑 = 𝟔
ANSWER: The check digit is 6.
INTERNATIONAL STANDARD BOOK NUMBER (ISBN)

Example 6:
b. Determine if the ISBN code 978 – 971 – 27 – 2770 – 4 is valid or not.
𝒙𝟏𝟑 = 𝟏𝟎 − 𝒙𝟏 + 𝟑𝒙𝟐 + 𝒙𝟑 + 𝟑𝒙𝟒 + 𝒙𝟓 + 𝟑𝒙𝟔 + 𝒙𝟕 + 𝟑𝒙𝟖 + 𝒙𝟗 + 𝟑𝒙𝟏𝟎 + 𝒙𝟏𝟏 + 𝟑𝒙𝟏𝟐 𝐦𝐨𝐝 𝟏𝟎

𝑥!. = 10 − 9 + 3 7 + 8 + 3 9 + 7 + 3 1 + 2 + 3 7 + 2 + 3 7 + 7 + 3 0 mod 10
𝑥!. = 10 − 128 mod 10
𝑥!. = 10 − 8
𝒙𝟏𝟑 = 𝟐
ANSWER: The ISBN code is NOT VALID.
UNIVERSAL PRODUCT CODE (UPC)

§ A 12-digit code that accompanies the bar code of a product.


§ For UPC, the 12th digit is the check digit.

Formula for the Check Digit:

𝒙𝟏𝟑 = 𝟏𝟎 − 𝟑𝒙𝟏 + 𝒙𝟐 + 𝟑𝒙𝟑 + 𝒙𝟒 + 𝟑𝒙𝟓 + 𝒙𝟔 + 𝟑𝒙𝟕 + 𝒙𝟖 + 𝟑𝒙𝟗 + 𝒙𝟏𝟎 + 𝟑𝒙𝟏𝟏 𝐦𝐨𝐝 𝟏𝟎


CREDIT CARDS
§ Credit card numbers can be easily checked
through the check digit.
§ In the Philippines, Visa and Mastercard in
the dominant credit cards in the market.
§ Normally, there are 16 digits but for some
Visa cards, there are only 13.
CREDIT CARDS
§ Credit card numbers can be checked by
doubling every other digit starting from the
first to the last digit (the last digit being the
check digit), and summing up all the
resulting numbers.
§ If the doubled digit results in a 2-digit
number, simply treat the two digits as
separate digits.
§ The card number is VALID only if the sum
of the digits under modulo 10 is congruent
to 0.
Example 7:
Determine which credit card number is valid and which is not.
a. 5234 8213 3410 1298
Digit 5 2 3 4 8 2 1 3 3 4 1 0 1 2 9 8

10 2 6 4 16 2 2 3 6 4 2 0 2 2 18 8
Doubled
(Alterna
te)

Sum = 1+0+2+6+4+1+6+2+2+3+6+4+2+0+2+2+1+8+8
= 60 ≅ 0 mod 10

Therefore, the credit card number is VALID.


Example 7:
Determine which credit card number is valid and which is not.
b. 6011 0123 9145 2317
Digit 6 0 1 1 0 1 2 3 9 1 4 5 2 3 1 7

12 0 2 1 0 1 4 3 18 1 8 5 4 3 2 7
Doubled
(Alterna
te)

Sum = 1+2+0+2+1+0+1+4+3+1+8+1+8+5+4+3+2+7
= 53 ≅ 3 mod 10

Therefore, the credit card number is INVALID.

You might also like