Computer and Data
Security
4th Class
Dr. Ashwaq Mahmood Alabaichi
2015-2016
lec.6
Mathematics of Cryptography
Modular
The modular of number can get from div tow number
and get reminder
Example:
12 div 3=4 because 4*3=12 and 12 mod 3=0(non
reminder)
12 div 5=2 because 5*2=10 and 12 mod 5=2
(reminder)
25 mod 6=1 can proof by 6*4=24 and reminder=1
R = a mod b
R = Remainder of dividing a by b.
Cont…
q=a/b
a = (q * b) + r 0≤r<b
r = a – (q * b )
q=23 /12 q=1
23=(1*12)+11 then 11=23-(1*12)
Rules :
If a>b then used r = a – (q * b) to find the reminder (R).
if a<b then r=a as reminder.
if a is negative(-) then used:
-a mod b=(-a +b) to get (+a mod b)
a=-11 ,b=7 find R
-11+7=-4 the get first positive integer
-4 +7=3.
[(a mod n)]+(b mod n)] mod n =(a + b) mod n
[(a mod n)]-(b mod n)] mod n =(a - b) mod n
[(a mod n)]*(b mod n)] mod n =(a *b) mod n
11 mod 8 =3; 15 mod 8 =7
[(11 mod 8 )+(15 mod 8)] mod 8 =10 mod 8 =2
(11+15) mod 8 = 26 mod 8 =2
[(11 mod 8 )-(15 mod 8)] mod 8 = -4 mod 8 =4
(11-15) mod 8 = -4 mod 8 =4
[(11 mod 8 )*(15 mod 8)] mod 8=21 mod 8 =5
(11*15) mod 8 = 165 mod 8 = 5
To find 117 mod 13 , we can proceed as follows:
117 mod 13
112 = 121 mod 13= 4
114 = 42 mod 13 = 3
111 = 111 mod 13=11
117 =4*3*11 ≡ 132 ≡ 2 mod 13 = 2
Euclidean Algorithm
Given two integers a and b (not both 0), a; b ≥0; a ≥ b, d =
GCD(a; b) may be found as follows:
Step 1 a = bq1 + r1 0 ≤ r1 ≤ b
Step 2 b = r1q2 + r2 0 ≤ r2 ≤ r1
Step 3 r1 = r2q3 + r3 0 ≤ r3 ≤ r2
Step n rn-2 = rn-1qn + rn 0 ≤ rn ≤ rn-1
Step n+1 rn-1 = rnqn+1 (so rn+1 = 0)
Then rn = GCD(a; b).
Find GCD(132،55 )using Euclidean Algorithm
132=55*2+22
55=22*2+11
22=11*2+0
GCD=11.
CONT…
GCD(27,18)
27= 18*1 +9
18= 9*2+0
GCD(27,18)=9
GCD(5,3)
5= 3*1+2
3=2*1+1
2=1*1+1
1=1*1+0
Two numbers are relatively prime when they share no factors in common
other than 1. In
other words, if the greatest common divisor of a and n is equal to 1.
This is written GCD(a, n) = 1
GCD(5,3)=1
GCD(123,4567)
4567=123*37+16
123=16*7+11
16=11*1+5
11=5*2+1
5=1*5+0
GCD(123,4567)=1
Another method
GCD(93,36)= GCD(36,93 mod 36)=GCD(36,21(
GCD(36,21)=GCD(21,36 mod 21) = GCD (21,15(
GCD(21,15)=GCD(15,21 mod 15)=GCD(15,6(
GCD(15,6)=GCD(6,15 mod 6)=GCD(6,3)
GCD(6,3)=GCD(3,6 mod 3) =GCD (3,0(
GCD (93,36)=3
. GCD OF Relative prime number (A,B) =1
Fermat's Theorem
Fermat's theorem states the following: If p is prime and a is a
positive integer not divisible by p, then
Equation:
ap-1 =1 mod p a = 7, p = 19
72 = 49 ≡11(mod 19)
74 ≡121 ≡7(mod 19)
78 ≡49 ≡11(mod 19)
716 ≡121 ≡7(mod 19)
ap-1 = 718 = 716 x 72 ≡7 x 11 ≡1(mod 19)
Least Common Multiple (LCM)
LCM(a, b) = a * b / GCD(a, b)
Example: LCM(4864,3458)
GCD(4864,3458)
4864 = 3458 * 1 + 1406
3458= 1046 *2 + 646
1406 = 646 *2 + 114
646 = 114* 5 + 76
114 = 67 * 1 + 38
76 = 38 *2 + 0
GCD(4864,3458) = 38
LCM(3864,3458) = (3864 * 3458 )/ GCD(4864,3458)
= 16819712 / 38
= 442624
Euler function
Euler function is an arithmetic function that counts
the positive integers less than M that are relatively
prime to M.
When the number(M) is prime number:
Φ(M)=M-1
Note: GCD(M, Φ(m))=1
Find Φ(5) : the number(5) is prime then
Φ(5)=5-1=4
The set or reduce are{1,2,3,4}
GCD(Φ(5),5)=1
GCD(5,1)=1 , GCD(2,5)=1 , GCD(3,5)=1 , GCD(4,5)=1
Cont…
When the M is not prime number :
Ф(Mr) = Mr-1 (M-1)
Find Ф(27) the number 27 is not prime then:
Ф(33)=3 2(3-1) =9*2 = 18
The set of reduce{1,2, 4, 5, 7, 8, 10, 11, 13, 14, 16,
17, 19, 20, 22, 23, 25, 26}
When the number composite of multi two
number (prime number) then
Ф(m1*m2) =(m1-1)(m2-1)
Find Ф(10) the number (10) make of (2*5) then :
Ф(10) = ( 2 * 5 ) = (2 -1) (5-1)
= 1* 4 = 4
The set of reduce={1,3,7,9}
Cont…
When the M is even number then :
Find Ф(20) the number 20 is make (4 * 5) then
4= 22 and 5= 51 then
Ф(20)= Ф(4,5)
Ф(20)= Ф(22) Ф(51)
Ф(20)= (22-1)(2-1) * (51-1)(5-1)= 2*4=8
The set of reduce ={1, 3, 7, 9, 11, 13, 17, 19}
Cont…
Write program to calculate Ф(Euler's).
Fast exponentiation algorithm
this algorithm used to find the large exponentiation by the
following
Cont…