Eng. Huda M. Dawoud

THE ISLAMIC UNIVERSITY OF GAZA
ENGINEERING FACULTY
DEPARTMENT OF COMPUTER ENGINEERING
DISCRETE MATHMATICS DISCUSSION – ECOM 2011
Eng. Huda M. Dawoud
November, 2015
DISCRETE MATHMATICS
ECOM 2012
Section 1: Divisibility and Modular Arithmetic
q= ⌊𝑎/𝑑⌋
9. What are the quotient and remainder when
a) 19 is divided by 7?
b) −111 is divided by 11?
c) 789 is divided by 23?
d) 1001 is divided by 13?
e) 0 is divided by 19?
f ) 3 is divided by 5?
g) −1 is divided by 3?
h) 4 is divided by 1?
Answer:
ENG. HUDA M. DAWOUD
DISCRETE MATHMATICS
ECOM 2012
ENG. HUDA M. DAWOUD
a) q = ⌊19/7⌋ = 2
r= 19 – (2 . 7) = 5
b) q = ⌊−111/11⌋ = -11
r= -111 – (-11 . 11) = 10
c) q = ⌊789/23⌋ = 34
r= 789 – (34 . 23) = 7
d) q = ⌊1001/13⌋ = 77
r= 1001 – (77 . 13) = 0
e) q = ⌊0/19⌋ = 0
r= 0 – (0 . 0) = 0
f) q = ⌊3/5⌋ = 0
r= 3 – (0 . 5) = 3
g) q = ⌊−1/3⌋ = -1
r= -1 – (-1 . 3) = 2
h) q = ⌊4/1⌋ = 4
r= 4 – (4 . 1) = 0
11. What time does a 12-hour clock read
a) 80 hours after it reads 11:00?
Answer:
(80 + 11) mod 12 = 7, the clock reads 07:00
12. What time does a 24-hour clock read
a) 100 hours after it reads 2:00?
Answer:
(100 + 2) mod 24 = 6, the clock reads 06:00
DISCRETE MATHMATICS
ECOM 2012
ENG. HUDA M. DAWOUD
13. Suppose that a and b are integers, a ≡ 4 (mod 13), and b ≡ 9 (mod 13).
Find the integer c with 0 ≤ c ≤ 12 such that
a) c ≡ 9a (mod 13).
:‫مالحظة مهمة جدا‬
‫يجب أن ننتبه جيدا إلى أن التعبير‬
b) c ≡ 11b (mod 13).
a ≡ 4(mod 13)
c) c ≡ a + b (mod 13).
d) c ≡ 2a + 3b (mod 13).
e) c ≡ a2 + b2 (mod 13).
f ) c ≡ a3 − b3 (mod 13).
‫يختلف عن التعبير‬
a = 4(mod 13)
a ‫ أما في الحالة األولى‬،‫ فقط‬4 ‫ قيمتها‬a ‫ففي الحالة الثانية‬
‫ إلخ‬.. 30 ‫ أو‬17 ‫ أو‬4 ‫تحتمل أكثر من قيمة حيث قد تساوي‬
a mod 13 = 4 mod 13 ‫بحيث‬
9‫و‬4 ‫ على أنها‬b‫و‬
a ‫وفي السؤال التالي نحن ال نعوض بقيمة‬
‫ راجع الخواص من الكتاب‬،mod‫ولكن نستخدم خواص ال‬
Answer:
‫والحظ الحل‬
a) (9 mod 13) · (a mod 13) mod 13 = (9.4) mod 13 = 36 mod 13 = 10
b) (11 mod 13) · (b mod 13) mod 13 = 99 mod 13 = 8
c) (a mod 13) + (b mod 13) mod 13 = (4 + 9) mod 13 = 0
d) 2 · 4 + 3 · 9 mod 13 = 35 mod 13 = 9
e) (a mod 13)2 + (b mod 13)2 mod 13 = (42 + 92) mod 13 = 97 mod 13= 6
f) (a mod 13)3 - (b mod 13)3 mod 13 = -665 mod 13 = -665 – (-52*13) =
11
DISCRETE MATHMATICS
ECOM 2012
ENG. HUDA M. DAWOUD
21. Evaluate these quantities.
a) 13 mod 3
b) −97 mod 11
c) 155 mod 19
d) −221 mod 23
Answer:
:‫تذكير‬
a) 13 = 4∙3 + 1, r= 1
𝑎 𝑚𝑜𝑑 𝑏 = 𝑎 − ⌊𝑎/𝑏⌋ ∗ 𝑏
b) -97 = -9∙11 + 3, r = -2
𝑎 = ⌊𝑎/𝑏⌋ ∗ 𝑏 + 𝑎 𝑚𝑜𝑑 𝑏
c) 155 = 8∙19 + 3, r = 3
d) -221 = -10∙23 + 9, r = 9
28. Decide whether each of these integers is congruent to 3 modulo 7.
a) 37
b) 66
c) −17
d) −67
Answer:
3 mod 7 = 3
a) 37 mod 7 = 2, thus 37 is not congruent to 3 mod 7  37 ≢ 3 mod 7
b) 66 ≡ 3 mod 7
c) -17 mod 7 = 4  -17 ≢ 3 mod 7
DISCRETE MATHMATICS
ECOM 2012
ENG. HUDA M. DAWOUD
d) -67 ≡ 3 mod 7
33. Find each of these values.
a) (992 mod 32)3 mod 15
Answer:
a) (9801 mod 32)3 mod 15 = (9)3 mod 15 = (729)3 mod 15 = 9
‫‪ENG. HUDA M. DAWOUD‬‬
‫‪DISCRETE MATHMATICS‬‬
‫‪ECOM 2012‬‬
‫‪Section 3: Primes and Greatest Common Divisors‬‬
‫‪1. Determine whether each of these integers is prime.‬‬
‫‪a) 21‬‬
‫‪b) 29‬‬
‫توضيح‪:‬‬
‫‪c) 71‬‬
‫في النظرية رقم ‪ ،2‬مذكور أن الرقم ال‪composite‬‬
‫دائما يوجد رقم ‪ prime‬يقبل القسمة عليه في‬
‫‪Answer:‬‬
‫المدى من ‪ 2‬إلى جذر هذا الرقم‪.‬‬
‫فحتى نثبت أن الرقم ‪ prime‬وليس ‪composite‬‬
‫نقوم بايجاد كل األرقام ال ‪ prime‬من ‪ 2‬إلى جذر‬
‫الرقم‬
‫فان كان الرقم ال يقبل القسمة على أي منها‪ ،‬إذن هو‬
‫ليس ‪composite‬‬
‫∤‬
‫ويكون في هذه الحالة ‪.prime‬‬
‫تعني ال تقبل القسمة‬
‫‪a) √21 = 4.58‬‬
‫‪2 ∤ 21‬‬
‫‪∴ 21 is prime‬‬
‫‪b) √29 = 5.28‬‬
‫‪2 ∤ 29, 3 ∤ 29, 5 ∤ 29‬‬
‫‪∴ 29 is prime‬‬
‫‪c) √71 = 8.42‬‬
‫‪2 ∤ 71, 3 ∤ 71, 5 ∤ 71, 7 ∤ 71‬‬
‫‪∴ 71 is prime‬‬
DISCRETE MATHMATICS
ECOM 2012
ENG. HUDA M. DAWOUD
3. Find the prime factorization of each of these integers.
a) 88
b) 126
c) 729
d) 1001
Answer:
a) 88 = 2 ∙44 = 2 ∙2∙22 = 2∙2∙2∙11
b) 126 = 2∙63 = 2∙3∙21 = 2∙3∙3∙ 7
c) 729 = 3∙243 = 3∙3∙81 = 3∙3∙3∙27 = 3∙3∙3 ∙3∙9 = 3∙3∙3∙3∙3∙3
d) 1001 = 7∙143 = 7∙11∙13
25. What are the greatest common divisor and the least common multiple of
these pairs of integers?
a) 37 · 53 · 73, 211 · 35 · 59
b) 11 · 13 · 17, 29 · 37 · 55 · 73
Answer:
a) GCD = 2min(0,11) ∙3min(7,5) ∙5min(3,9) ∙7min(3,0) = 20∙35∙53 ∙70 = 35∙53
LCM = 2max(0,11) ∙3max(7,5) ∙5max(3,9) ∙7max(3,0) = 211 ∙37 ∙ 59∙73
b) GCD = 2min(0,9) ∙3min(0,7) ∙5min(0,5) ∙7min(0,3) ∙11min(1,0) ∙13min(1,0) ∙17min(1,0)
= 20∙30∙ 50∙ 70∙110∙130∙170 = 1
DISCRETE MATHMATICS
ECOM 2012
ENG. HUDA M. DAWOUD
LCM = 2max(0,9) . 3 max (0,7) . 5 max (0,5) . 7 max (0,3) . 11 max (1,0) . 13 max (1,0) . 17 max(1,0)
= 29. 37. 55. 73. 111. 131. 171
33. Use the Euclidean algorithm to find
a) gcd(12, 18).
b) gcd(111, 201).
Answer:
a) gcd(12, 18) = gcd(12, 18 mod 12) = gcd(12, 6) = gcd(6, 12 mod 6) =
gcd(6, 0) = 6.
b) gcd(111,201) = gcd(111,90) = gcd(90,21) = gcd(21,6) = gcd(6,3) =
gcd(3,0) = 3
DISCRETE MATHMATICS
ECOM 2012
ENG. HUDA M. DAWOUD
39. Using the method followed in Example 17, express the greatest common
divisor of each of these pairs of integers as a linear combination of these
integers.
a) 10, 11
b) 21, 44
Answer:
a) gcd(10, 11) = 1, and 1 = 11 - 10 = ( -1) · 10 + 1 · 11.
b) gcd(21, 44)= 1, and
44 = 2∙21 + 2
21= 10∙2 + 1
 1 = 21 – 10∙2
= 21 –10∙ (44 – 2∙21)
= 21 – 10∙44 + 10 ∙2∙21
= 21 – ( 10 ∙44) + ( 20∙21)
= ( 21∙21 ) – ( 10 ∙44)
DISCRETE MATHMATICS
ECOM 2012
ENG. HUDA M. DAWOUD
Section 4: Solving Congruences
:‫توضيح‬
‫وعندما يطلب حل معادلة على هذا الشكل‬
ax ≡ b mod m ‫ هو معادلة على الشكل‬linear congruences‫ال‬
.‫ التي تحقق المعادلة‬x ‫يعني أننا يجب أن نجد قيم‬
‫ حيث أن‬inverse ‫ نحتاج أن نجد ما يسمى بال‬x ‫حتى نجد‬
a’a ≡ 1 mod m
‫تابع األسئلة لتتضح الفكرة‬
1. Show that 15 is an inverse of 7 modulo 26.
Answer:
We want to find if 15.7 ≡ 1 mod 26 or not
105 mod 26 = 1 and 1 mod 26 = 1, which means that 15.7 ≡ 1 mod 26 is
true and 15 is an inverse of 7 mod 27
DISCRETE MATHMATICS
ECOM 2012
ENG. HUDA M. DAWOUD
Note:
To find an inverse of a mod m:
1. a and m first must be relatively prime that gcd(a,m) = 1
2. From Bezout’s Theorm, we can write sa + tm = 1
3. s here is the inverse of a mod mas
Now see the answer
5. Find an inverse of a modulo m for each of these pairs of relatively prime
integers using the method followed in Example 2.
a) a = 4, m = 9
b) a = 19, m = 141
Answer:
a) 9=2·4 + 1
4=4·1
Now, 1 = 9-2·4
-2 is an inverse of 4 mod 9
b) 141=7∙19 + 8
19 = 2∙8 + 3
8=2·3+2
3=1·2+1
2=2·1
Now, 1=3-1·2
DISCRETE MATHMATICS
ECOM 2012
ENG. HUDA M. DAWOUD
= 3 - 1∙ (8 - 2∙3) = 3∙3 - 1∙ 8
= 3∙ (19 - 2 ∙8) - 1∙8 = 3 ∙19 - 7∙8
= 3∙19 - 7∙ (141 - 7. 19) = (-7) ∙141+52∙19
52 is an inverse of 19 mod 141
11. Solve each of these congruences using the modular inverses found in
parts (b) of Exercise 5.
a) 19x ≡ 4 (mod 141)
Answer:
a) In Exercise 5b we found that an inverse of 19 modulo 141 is 52.
That 19*52 ≡ 1 (mod 141).
Therefore we multiply both sides of this equation by 52.
19*52 * x ≡ 4*52 (mod 141)
(19*52 mod 141)1(x mod 141) = 208 mod 141
x ≡ 67 (mod 141)
:‫مالحظة‬
a’a ≡ 1 mod m
linear congruence‫ إلكمال حل ال‬inverse ‫بعد إيجاد ال‬
inverse‫نقوم بضرب طرفي المعادلة بال‬
19*52*x ≡ (4*52) mod 141
‫وحسب الخاصية السابقة‬
ab mod c = (a mod c)(b mod c) mod c
((19*52) mod 141)1 (x mod 141) ≡ (4*52) mod 141
x ≡ (4*52) mod 141
..‫وهو المطلوب‬
DISCRETE MATHMATICS
ECOM 2012
ENG. HUDA M. DAWOUD
Section 5: Application of Congruences
:‫مالحظة‬
‫ نالحظه في البرامج التي تصمم إلختيار رقم‬،‫إيجاد أرقام عشوائية يلزم في استخدامات متعددة‬
..‫ واأللعاب الورقية وغيرها‬،‫فائز ضمن مجموعة من األرقام‬
linear ‫ إحداها ال‬،‫لذلك هناك أكثر من من طريقة إليجاد هذه األرقام برمجيا تتفاوت في ما بينها‬
congruential method
5. What sequence of pseudorandom numbers is generated using the linear
congruential generator xn+1 = (3xn + 2) mod 13 with seed x0 = 1?
Answer:
x1 = (3 · x0 + 2) mod 13 = (3 · 1 + 2) mod 13 = 5.
x2 = (3 · x1 + 2) mod 13 = (3 · 5 + 2) mod 13 = 17 mod 13 = 4.
x3 = (3 · 4 + 2) mod 13 = 1. Because this is the same as x0, the sequence
repeats from here on out. So the sequence is 1, 5, 4, 1, 5, 4, 1, 5, 4, ....
DISCRETE MATHMATICS
ECOM 2012
ENG. HUDA M. DAWOUD
Section 6: Cryptography
1. Encrypt the message DO NOT PASS GO by translating the letters into
numbers, applying the given encryption function, and then translating the
numbers back into letters.
b) f(p) = (p + 13) mod 26
Answer:
Letter
Before Encryption
After Encryption
Letter
D
4
17
Q
O
15
2
B
N
14
1
A
O
15
2
B
T
20
7
G
P
16
3
C
A
1
14
N
S
19
6
F
f(4) = (4+13 mod 26) = 17
f(15) = (15+13 mod 26) = 28 mod 26 = 2 and so on…
To translate it back into letter (decrypt it) we use
f-1(p) = (p – 13) mod 26.Try it yourself
S
19
6
F
G
7
20
T
O
15
2
B
DISCRETE MATHMATICS
A
00
K
10
U
20
B
01
L
11
V
21
C
02
M
12
W
22
ECOM 2012
D
03
N
13
X
23
E
04
O
14
Y
24
F
05
P
15
Z
25
ENG. HUDA M. DAWOUD
G
06
Q
16
H
07
R
17
I
08
S
18
J
09
T
19
25. Encrypt the message UPLOAD using the RSA system with n = 53 · 61 and
e = 17, translating each letter into integers and grouping together pairs of
integers, as done in Example 8.
Answer:
UPLOAD = 20 15 11 14 00 03  2015 1114 0003
C = Me mod n = M17 mod 3233
Note that n = 53 · 61 = 3233 and that gcd(e, (p - 1) ( q - 1)) = gcd(l 7, 52 ·
60) = 1, as it should be.
C1 = (2015)17 mod 3233 = 2545
C2 = (1114)17 mod 3233 = 2757
‫‪ECOM 2012‬‬
‫‪ENG. HUDA M. DAWOUD‬‬
‫‪DISCRETE MATHMATICS‬‬
‫‪C3 = (0003)17 mod 3233 = 1211‬‬
‫‪The message would be sent as 2545 2757 1211‬‬
‫مالحظة‪:‬‬
‫و‪ n‬التي تم‬
‫الرسالة المشفرة باستخدام ال ‪ RSA‬ال يمكن فك تشفيرها إال إزا علمنا قيمة ‪e‬‬
‫من خاللها التشفير‪ ،‬حيث ال‪ e‬وال )‪ n=(p-1)(q-1‬تكون بمثابة كلمة السر التي تمكن من‬
‫يعرفها من قراءة الرسالة الصحيحة‪.‬‬
‫حيث نقوم بإيجاد ‪ d‬الذي هو ‪ inverse‬ل‪ e mod n‬كما تعلمنا في ‪section 4‬‬
‫فيما يلي سنقوم بفك التشفير للمثال السابق‪..‬‬
‫)‪ We need to get d which is the inverse of e mod (p-1)(q-1‬‬
‫‪Note that we have chosen e, p, q such that the gcd(e, (p-1)(q-1)) =1, so the inverse of‬‬
‫‪e mod n exists.‬‬
DISCRETE MATHMATICS
ECOM 2012
ENG. HUDA M. DAWOUD
3233 = 190∙17+ 3
17 = 5∙3 + 2
3 = 2∙1 + 1
Now,
1 = 3 - 2∙1
= 3 – 2(17 - 5∙3)
=3 – 2∙17 + 2∙5∙3
= – 2∙17 + 11∙3
= -2.17 + 11 (3233 - 190∙17)
= -2.17 + 11∙3233 - 2090∙17
= 11∙3233 - 2092∙17
d(2092) is the inverse of e(17) mod n(3233)
2545 2757 1211
M = Cd mod n
M1 = C12092 mod 3233
= (2545) 2092 mod 3233  ‫ ويكفي الوصول في الحل حاليا ً لهنا‬،‫حسابها ليس سهل‬
= 2015
M2 = (2757) 2092 mod 3233
= 1114
M3 = (1211) 2092 mod 3233
= 0003