Professional Documents
Culture Documents
UNIT: CRYPTOGRAPHY
YEAR: 4.2
Question 1: Prove the following
Python Code
j=3
k=9
i = (int)(1e9+7)
result = pow(j, k) % i
print (result)
b) The sieve of Eratosthenes
It is used to find all primes not exceeding a specified positive integer
The following python code is used to find the primes not exceeding 100
Python Code
def Sieve_Of_Eratosthenes (number):
prime = [True for i in range(number+1)]
p=2
while (p * p <= number):
if (prime[p] == True):
for i in range (p * p, number+1, p):
prime[i] = False
p += 1
for p in range (2, number+1):
if prime[p]:
print(p)
if __name__ == '__main__':
number = 100
print ("The following are the prime numbers not exceeding", number),
Sieve_Of_Eratosthenes (number)
Question 3: Let ‘m’ be the gcd of 117 and 299, find ‘m’ using the Euclidean algorithm
Let a = b q + r, where a, b, q and r, are integers. Then gcd (a, b) = gcd (b, r)
a = 299
b = 117
Therefore;
299 = (117 x 2) + 65
117 = (65 x 1) + 52
65 = (52 x 1) + 13
52 = (13 x 4) + 0
Therefore m = 13
Python Code
if a < b:
print ()
while b! = 0:
(a, b) = (b, a % b)
return a
The python code above has been tested using ‘question 3’
The new code should return the gcd of a and b and the Bezouts coefficients x and y, such that
𝑎𝑥 + 𝑏𝑦 = 1
Python Code
if a == 0:
return b,0,1
x = b1 - (b//a) * a1
y = a1
return GCD, x, y
Question 6: Find the integers p and q, solution to 1002𝑝 + 71𝑞 = m
71 = (8 x 8) + 7
8 = (7 x 1) + 1
7 = (1 x 7) + 0
GCD = 1
1=8–7
= 8 - (71 – 8 x 8)
= 8 – 71 + 8 x 8
= 72 -71
= (9 x 8) – 71
= 9 x 1002 – 71 (126 + 1)
= 9 x 1002 – 71 x 127
Therefore; p = 9, q = -127
Question 7: Determine whether the equation 486x + 222y = 6 has a solution
486 = (222 x 2) + 42
222 = (42 x 5) + 12
42 = (12 x 3) + 6
12 = (6 x 2) + 0
To get x and y:
6 = 42 – 12 x 3
= 42 – 3 (222 – 42 x 5)
= 42 – 3 x 222 + 3(42 x 5)
= 42 – 3 x 222 + 630
= -3 x 222 + 16 x 42
11 = (3 x 3) + 2
3 = (2 x 1) + 1
2 = (1 x 2) + 0
GCD = 1
To get x and y:
1=3–2
= 3 – (11 – 3 x 3)
= 3 – 11 + 3 x 3
= 3 – 11 + 3 (421 – 11 x 38)
= 3 – 11 + 1263 – 1254
= 421(1 + 3) – 11 (1 + 38 + 114)
Therefore; x = 4, y = -153