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

Lecture 10 Modular Arithmetic

Uploaded by

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

Lecture 10 Modular Arithmetic

Uploaded by

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

MODULAR ARITHMETIC

Modulo n

𝑎−𝑏
Two integers a and b are said to be congruent modulo n, where n is a natural number, if 𝑛 is
an integer. In this case, we write a ≡b mod n. The number n is called the modulus. The
statement a≡b mod n is called a congruence.

Example 1: Determine whether a congruence is true


Determine whether the congruence is true.
a. 29 ≡ 8 mod 3

29−8 21
Find = = 7. 𝐵𝑒𝑐𝑎𝑢𝑠𝑒 7 𝑖𝑠 𝑎𝑛 𝑖𝑛𝑡𝑒𝑔𝑒𝑟, 29 ≡ 8 𝑚𝑜𝑑 3 𝑖𝑠 𝑎 𝑡𝑟𝑢𝑒 𝑐𝑜𝑛𝑔𝑟𝑢𝑒𝑛𝑐𝑒.
3 3

b. 15 ≡ 4 mod 6
15−4 11 11
Find 6 = 6 . 𝐵𝑒𝑐𝑎𝑢𝑠𝑒 6 𝑖𝑠 𝑛𝑜𝑡 𝑎𝑛 𝑖𝑛𝑡𝑒𝑔𝑒𝑟, 15 ≡ 4 𝑚𝑜𝑑 6 𝑖𝑠 𝑛𝑜𝑡 𝑎 𝑡𝑟𝑢𝑒 𝑐𝑜𝑛𝑔𝑟𝑢𝑒𝑛𝑐𝑒.
Example 2: a Day of the Week

July 4, 2010, was a Sunday. What day of the week is July 4, 2015?

Solution: There are 5 years between the two dates. Each year has
365 days except 2012, which has one extra day because it is a leap
year. So the total number of days between the two dates is 5 x 365
+ 1 = 1826. Because 1826 ÷ 7 = 260 remainder 6, 1826 ≡ 6 mod 7.
Any multiple of 7 days past a given day will be the same day of the
week. So the day of the week 1826 days after July 4, 2010, will be
the same as the day 6 days after July 4, 2010. Thus July 4, 2015,
will be a Saturday.
Arithmetic Operations
Arithmetic modulo n, where n is a natural number,
uses a variation of the standard rules of arithmetic
we have used before. Perform the arithmetic
operation and then divide by the modulus. The
answer is the remainder. Thus the result of an
arithmetic operation mod n is always a whole
number less than n.
Example 3: Addition modulo n
Evaluate: 23 + 38 𝑚𝑜𝑑 12

Solution

Add 23 + 38 to produce 61. Then divide by the modulus, 12. The


answer is the remainder.

61 ÷ 12 = 5, 𝑟𝑒𝑚𝑎𝑖𝑛𝑑𝑒𝑟 𝑖𝑠 1

The answer is 1.
Example 4: Subtraction modulo n
Evaluate each of the following:
a. (33 – 16) mod 6 b. (14 – 27) mod 5

Solution
a. Subtract 33 – 16 = 17. The result is positive. Divide the
difference by the modulus, 6. The answer is the remainder

17 ÷ 6 = 2, 𝑟𝑒𝑚𝑎𝑖𝑛𝑑𝑒𝑟 𝑖𝑠 5

(33- 16) mod 6 ≡ 5.


Example 5: Calculating Times
Disregarding A.M. or P.M., if it is 5 o’clock now, what time was it 57
hours ago?

Solution: The time can be determined by calculating (5 – 57) mod 12.


Because 5 – 57 = -52 is a negative number, find a whole number x less
than the modulus 12, so that -52 ≡ x mod 12. This means to find x so
−52−𝑥 −(52+𝑥)
that 12 = 12 is an integer. Evaluating the expression for whole
−(52+8) 60
number values of x less than 12, we have, when x = 8, = − 12
=
12
− 5, an integer. Thus (5 – 57) mod 12 ≡ 8. Therefore, if it is 5 o’clock
now, 57 hours ago it was 8 o’clock.
Example 6: Multiplication modulo n
Evaluate (15 * 23) mod 11

Solution
Find the product 15 * 23 and then divide by the modulus, 11. The
answer is the remainder.
345 ÷ 11 = 31, remainder is 4.

So, the answer is 4.


Example 7: Solve a Congruence Equation
Solve 2x + 1 ≡ 3 mod 10
Solution
Beginning with 0, substitute each whole number less than 10 into the congruence
equation.
𝒙=𝟎 𝟐 𝟎 + 𝟏 ≠ 𝟑 𝒎𝒐𝒅 𝟏𝟎 𝑵𝒐𝒕 𝒂 𝒔𝒐𝒍𝒖𝒕𝒊𝒐𝒏
𝒙=𝟏 𝟐 𝟏 + 𝟏 ≠ 𝟑 𝒎𝒐𝒅 𝟏𝟎 𝑨 𝒔𝒐𝒍𝒖𝒕𝒊𝒐𝒏
𝒙=𝟐 𝟐 𝟐 + 𝟏 ≠ 𝟑 𝒎𝒐𝒅 𝟏𝟎 𝑵𝒐𝒕 𝒂 𝒔𝒐𝒍𝒖𝒕𝒊𝒐𝒏
𝒙=𝟑 𝟐 𝟑 + 𝟏 ≠ 𝟑 𝒎𝒐𝒅 𝟏𝟎 𝑵𝒐𝒕 𝒂 𝒔𝒐𝒍𝒖𝒕𝒊𝒐𝒏
𝒙=𝟒 𝟐 𝟒 + 𝟏 ≠ 𝟑 𝒎𝒐𝒅 𝟏𝟎 𝑵𝒐𝒕 𝒂 𝒔𝒐𝒍𝒖𝒕𝒊𝒐𝒏
𝒙=𝟓 𝟐 𝟓 + 𝟏 ≠ 𝟑 𝒎𝒐𝒅 𝟏𝟎 𝑵𝒐𝒕 𝒂 𝒔𝒐𝒍𝒖𝒕𝒊𝒐𝒏
𝒙=𝟔 𝟐 𝟔 + 𝟏 ≠ 𝟑 𝒎𝒐𝒅 𝟏𝟎 𝑨 𝒔𝒐𝒍𝒖𝒕𝒊𝒐𝒏
𝒙=𝟕 𝟐 𝟕 + 𝟏 ≠ 𝟑 𝒎𝒐𝒅 𝟏𝟎 𝑵𝒐𝒕 𝒂 𝒔𝒐𝒍𝒖𝒕𝒊𝒐𝒏
𝒙=𝟖 𝟐 𝟖 + 𝟏 ≠ 𝟑 𝒎𝒐𝒅 𝟏𝟎 𝑵𝒐𝒕 𝒂 𝒔𝒐𝒍𝒖𝒕𝒊𝒐𝒏
𝒙=𝟗 𝟐 𝟗 + 𝟏 ≠ 𝟑 𝒎𝒐𝒅 𝟏𝟎 𝑵𝒐𝒕 𝒂 𝒔𝒐𝒍𝒖𝒕𝒊𝒐𝒏

The solutions between 0 and 9 are 1 and 6; the remaining solutions are determined by
repeatedly adding the modulus, 10, to these solutions. The solutions are 1, 6, 11, 16,
21, 26, …
Additive and Multiplicative Inverse in Modular Arithmetic

Recall that if the sum of two numbers is 0, then the numbers are additive
inverses of each other. For instance, 8 + (-8) = 0, so 8 is the additive inverse of -8
and -8 is the additive inverse of 8.
The same concept applies in modular arithmetic. For example, (3 + 5) ≡ 0
mod 8. Thus, in mod 8 arithmetic, 3 is the additive inverse of 5, and 5 is the
additive inverse of 3. Here we consider only those whole numbers smaller than
the modulus. Note that 3 + 5 = 8; that is, the sum of a number and its additive
inverse equals the modulus. Using this fact, we can easily find the additive
inverse of a number for any modulus. For instance, in mod 11 arithmetic, the
additive inverse of 5 is 6 because 5 +6 = 11.

Example 8 Find the additive inverse


Find the additive inverse of 7 in mod 16 arithmetic.
Solution: In mod 16 arithmetic, 7 + 9 = 16, so the additive inverse of 7 is 9.
Additive and Multiplicative Inverse in Modular Arithmetic

If the product of two numbers is 1, then the numbers are


multiplicative inverses of each other. For instance, 2 * ½ = 1, so 2 is
the multiplicative inverse of ½, and ½ is the multiplicative inverse of
2. The same concept applies to modular arithmetic (although the
multiplicative inverses will always be natural numbers). For example,
in mod 7 arithmetic, 5 is the multiplicative inverse of 3 ( and 3 is the
multiplicative inverse of 5) because 5 * 3 = 1 mod 7. (Here we will
concern ourselves only with natural numbers less than the modulus.)
To find the multiplicative inverse of a mod m, solve the modular
equation ax ≡ 1 mod m for x.
Additive and Multiplicative Inverse in Modular Arithmetic
Example 9 Find a Multiplicative Inverse

In mod 7 arithmetic, find the multiplicative inverse of 2.

Solution: To find the multiplicative inverse of 2, solve the equation 2𝑥 ≡


1𝑚𝑜𝑑 7 by trying different natural number values of x less than the modulus.

2𝑥 ≡ 1 𝑚𝑜𝑑 7
2(1) ≠ 1 𝑚𝑜𝑑 7 Try x = 1
2(2) ≠ 1 𝑚𝑜𝑑 7 Try x = 2
2(3) ≠ 1 𝑚𝑜𝑑 7 Try x = 3
2(4) ≠ 1 𝑚𝑜𝑑 7 Try x = 4

In mod 7 arithmetic, the multiplicative inverse of 2 is 4.


Applications of Modular Arithmetic
ISBN and UPC

The first three digits of an ISBN are 978, the next digit indicates the country in
which the publisher is incorporated (0, and sometimes 1, for books written in
English), the next two to seven digits indicate the publisher, the next group of
digits indicates the title of the book, and the last digit (the 13th one) is called a
check digit.

If we label the first digit of an ISBN 𝑑1 , the second digit 𝑑2 , and so on to the 13th
digit 𝑑13 , then the check digit is chosen to satisfy the following congruence.

Formula for the ISBN Check Digit


𝑑13 = 10 − (𝑑1 +3𝑑2 +𝑑3 + 3𝑑4 + 𝑑5 + 3𝑑6 + 𝑑7 + 3𝑑8 + 𝑑9 + 3𝑑10 + 𝑑11 + 3𝑑12 )mod
10
If 𝑑13 = 10, then the check digit is 0.
Example 10 Determine a Check Digit for an ISBN

Determine the ISBN check digit for the book The Equation that
Couldn’t Be Solved by Mario Livio. The first 12 digits of the ISBN are
978-0-7432-5820-?

Solution:

𝑑13
≡ 10
− ሾ9 + 3 7 + 8 + 3 0 + 7 + 3 4 + 3 + 3 2 + 5 + 3 8 + 2
UPC (Universal Product Code)

The UPC is a 12-digit number that satisfies a congruence equation that is similar
to the one for ISBNs. The last digit is the check digit. If we label the 12 digits of
the UPC as 𝒅𝟏 , 𝒅𝟐 ,…, 𝒅𝟏𝟐 , we can write a formula for the UPC check digit 𝒅𝟏𝟐 .

Formula for the UPC Check Digit

𝑑12 = 10 − (3𝑑1 +𝑑2 +3𝑑3 + 𝑑4 + 3𝑑5 + 𝑑6 + 3𝑑7 + 𝑑8 + 3𝑑9 + 𝑑10 + 3𝑑11 ) mod 10
If 𝑑13 = 10, then the check digit is 0.
Example 11

Find the check digit for the DVD release of the film Alice in Wonderland. The
first 11 digits are 7-86936-79798-?

Solution:

𝑑12 = 10 − ሾ3 7 + 8 + 3 6 + 9 + 3 3 + 6 + 3 7 + 9 + 3 7 + 9 + 3 8 ] mod 10

𝑑12 = 10 − 155mod 10 = 10 − 5 = 5

The check digit is 5.


Credit Card Numbers

Companies that issue credit cards also use modular arithmetic to determine
whether a credit card number is valid. This is especially important in e-commerce,
where credit card information is frequently sent over the Internet. The primary
coding method is based on the Luhn algorithm, which uses mod 10 arithmetic.

Credit card numbers are normally 13 to 16 digits long. The first one to four digits
are used to identify the card issuer. The table below shows the identification
prefixes used by four popular card issuers.
Card issuer Prefix Number of digits
MasterCard 51 to 55 16
Visa 4 13 or 16
American Express 34 or 37 15
Discover 6011 16
Credit Card Numbers
The Luhn algorithm, used to determine whether a credit card number is valid, is
calculated as follows: Beginning with the next-to-last digit (the last digit is the check
digit) and reading from right to left, double every other digit. If a digit becomes a
two-digit number after being doubled, treat the number as two individual digits. Now
find the sum of the new list of digits; the final sum must equal 0 mod 10.

Example 12 Determine a Valid Credit Card Number


Determine whether 5234 8213 3410 1298 is a valid credit card number.
Solution: Highlight every other digit, beginning with the next to last digit and reading
from right to left.
5 2 3 4 8 21 3 3 4 1 0 1 2 9 8
Next double each of the highlighted digits.
10 2 6 4 16 2 2 3 6 4 2 0 2 2 18 8
Finally, add all digits, treating two-digit numbers as two single digits.
(1+0) + 2 + 6 + 4 + (1+6) + 2 + 2 +3 +6 + 4 +2 + 0 + 2 + 2 + (1+8) + 8 = 60
Because 60 = 0 mod 10, this is a valid credit card number.
Cryptology
-is the study of making and breaking secret codes.

Plaintext is a message before it is coded. The line


SHE WALKS IN BEAUTY LIKE THE NIGHT
From Lord Byron’s poem “She Walks in Beauty” is in plaintext. Ciphertext is the
message after it has been written in code. The line
ODA SWHGO EJ XAWQPU HEGA PDA JECDP
Is the same line of the poem in ciphertext.

The method of changing from plaintext to ciphertext is called encryption.


Numerical Equivalents for the Letters of the Alphabet

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

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 0
If the encrypting code is to shift each letter of the plaintext message m
positions, then the corresponding letter in the ciphertext message is given by 𝑐 ≡
𝑝 + 𝑚 𝑚𝑜𝑑 26, where p is the numerical equivalent of the plaintext letter and c
is the numerical equivalent of the ciphertext letter. The letter Z is coded as 0
because 26 ≡0 mod 26.

Each letter in Lord Byron’s poem was shifted 22 positions (m = 22) to the right.
To code the plaintext letter S in the word SHE, we use the congruence 𝑐 ≡
𝑝 + 𝑚 𝑚𝑜𝑑 26.

𝑐 ≡ 𝑝 + 𝑚 𝑚𝑜𝑑 26
𝑐 ≡ 19 + 22 𝑚𝑜𝑑 26
𝑐 ≡ 41 𝑚𝑜𝑑 26
𝑐 = 15
The 15th letter is O. Thus S is coded as O.
Once plaintext has been converted to ciphertext, there must be a
method by which the person receiving the message can return the
message to plaintext. For the cyclical code, the congruence is 𝑝 ≡
𝑐 + 𝑛 𝑚𝑜𝑑 26, where p and c are defined as before and n = 26 – m.
The letter O in ciphertext is decoded below using the congruence 𝑝 ≡
𝑐 + 𝑛 𝑚𝑜𝑑 26.
𝑝 ≡ 𝑐 + 𝑛 𝑚𝑜𝑑 26
𝑝 ≡ 15 + 4 𝑚𝑜𝑑 26
𝑝 ≡ 19 𝑚𝑜𝑑 26
𝑝 = 19
The 19th letter is S. Thus O is decoded as S.
Example 13 Write Messages Using Cyclical Coding

Use the cyclical alphabetic encrypting code that shifts each


letter 11 positions to

a. Code CATHERINE THE GREAT

b. Decode TGLY ESP EPCCTMWP


Example 13 Write Messages Using Cyclical Coding
a. Code CATHERINE THE GREAT
Solution: The encrypting congruence is 𝑐 ≡ 𝑝 + 11 𝑚𝑜𝑑 26. Replace p by the
numerical equivalent of each letter of plaintext and determine c. The results for
CATHERINE are shown below.
C 𝑐 ≡ 3 + 11 𝑚𝑜𝑑 26 ≡ 14 mod 26 ≡ 14 Code C as N
A 𝑐 ≡ 1 + 11 𝑚𝑜𝑑 26 ≡ 12 mod 26 ≡ 12 Code A as L
T 𝑐 ≡ 20 + 11 𝑚𝑜𝑑 26 ≡ 31 mod 26 ≡ 14 Code T as E
H 𝑐 ≡ 8 + 11 𝑚𝑜𝑑 26 ≡ 19 mod 26 ≡ 19 Code H as S
E 𝑐 ≡ 5 + 11 𝑚𝑜𝑑 26 ≡ 16 mod 26 ≡ 16 Code E as P
R 𝑐 ≡ 18 + 11 𝑚𝑜𝑑 26 ≡ 29 mod 26 ≡ 14 Code R as C
I 𝑐 ≡ 9 + 11 𝑚𝑜𝑑 26 ≡ 20 mod 26 ≡ 20 Code I as T
N 𝑐 ≡ 14 + 11 𝑚𝑜𝑑 26 ≡ 25 mod 26 ≡ 25 Code N as Y
E 𝑐 ≡ 5 + 11 𝑚𝑜𝑑 26 ≡ 16 mod 26 ≡ 16 Code E as P

Continuing, the plaintext would be coded as NLESPCTYP ESP RCPLE


Example 13 Write Messages Using Cyclical Coding
b. Decode TGLY ESP EPCCTMWP
Solution: Because m = 11, n = 26 -11 = 15. The ciphertext is decoded by using the
congruence 𝑝 ≡ 𝑐 + 15 𝑚𝑜𝑑 26. The results for TGLY are shown below.

T 𝑝 ≡ 20 + 15 𝑚𝑜𝑑 26 ≡ 35 𝑚𝑜𝑑 26 ≡ 9 Decode T as I

G 𝑝 ≡ 7 + 15 𝑚𝑜𝑑 26 ≡ 22 𝑚𝑜𝑑 26 ≡ 22 Decode G as V

L 𝑝 ≡ 12 + 15 𝑚𝑜𝑑 26 ≡ 27 𝑚𝑜𝑑 26 ≡ 1 Decode L as A

Y 𝑝 ≡ 25 + 15 𝑚𝑜𝑑 26 ≡ 40 𝑚𝑜𝑑 26 ≡ 14 Decode Y as N

Continuing, the ciphertext would be decoded as IVAN THE TERRIBLE.


Example 14 Encode a Message
Use the congruence 𝑐 ≡ 5𝑝 + 2 𝑚𝑜𝑑 26 to encode the message LASER PRINTER.

Solution: The encrypting congruence is 𝑐 ≡ 5𝑝 + 2 𝑚𝑜𝑑 26. Replace p by the


numerical equivalent of each letter from the table and determine c. The results
for LASER are shown below.

L 𝑐 ≡ 5 ∗ 12 + 2 𝑚𝑜𝑑 26 ≡ 62 𝑚𝑜𝑑 26 = 10 Code L as J

A 𝑐 ≡ 5 ∗ 1 + 2 𝑚𝑜𝑑 26 ≡ 7𝑚𝑜𝑑 26 = 7 Code A as G

S 𝑐 ≡ 5 ∗ 19 + 2 𝑚𝑜𝑑 26 ≡ 97𝑚𝑜𝑑 26 = 19 Code S as S

E 𝑐 ≡ 5 ∗ 5 + 2 𝑚𝑜𝑑 26 ≡ 27𝑚𝑜𝑑 26 = 1 Code E as A

R 𝑐 ≡ 5 ∗ 18 + 2 𝑚𝑜𝑑 26 ≡ 92𝑚𝑜𝑑 26 = 14 Code R as N


Continuing, the plaintext is coded in ciphertext as JGSAN DNUTXAN
Example 15 Decode a Message
Decode the message ACXUT CXRT, which was encrypted using the
congruence 𝑐 ≡ 3𝑝 + 5 𝑚𝑜𝑑 26.
Solution: Solve the congruence equation for p.
𝑐 = 3𝑝 + 5
𝑐 − 5 = 3𝑝
9 𝑐 − 5 = 9 3𝑝 9(3) = 27 and 27 = 1 mod 26
9 𝑐 − 5 𝑚𝑜𝑑 26 ≡ 𝑝
The decoding congruence is 𝑝 ≡ 9 𝑐 − 5 𝑚𝑜𝑑 26.
Using this congruence, we will show the details for decoding ACXUT.
A 9 1 − 5 𝑚𝑜𝑑 26 ≡ −36 𝑚𝑜𝑑 26 ≡ 16 Decode A as P.
C 9 3 − 5 𝑚𝑜𝑑 26 ≡ −18 𝑚𝑜𝑑 26 ≡ 8 Decode C as H.
X 9 24 − 5 𝑚𝑜𝑑 26 ≡ 171 𝑚𝑜𝑑 26 ≡ 15 Decode X as O.
U 9 21 − 5 𝑚𝑜𝑑 26 ≡ 144 𝑚𝑜𝑑 26 ≡ 14 Decode U as N.
T 9 20 − 5 𝑚𝑜𝑑 26 ≡ 135 𝑚𝑜𝑑 26 ≡ 5 Decode T as E.

Continuing, we would decode the message as PHONE HOME.

You might also like