Name: Shirleen Chelangat Ruttoh. REG NO: SCT 212-0069/2018. Unit: Fundamentals of Computer Security Tech. Unit Code: BCT 2306. Assignment 1
Name: Shirleen Chelangat Ruttoh. REG NO: SCT 212-0069/2018. Unit: Fundamentals of Computer Security Tech. Unit Code: BCT 2306. Assignment 1
Name: Shirleen Chelangat Ruttoh. REG NO: SCT 212-0069/2018. Unit: Fundamentals of Computer Security Tech. Unit Code: BCT 2306. Assignment 1
Answer.
def ModularExponentiation(x, p, m):
X=x
P=p
Y=1
while E > 0:
if E % 2 == 0:
X = (X * X) % m
else:
Y = (X * Y) % m
E=E-1
return Y
b) The sieve of Eratosthenes (10 marks)
Answer.
def SieveOfEratosthenes(n):
prime = [True for i in range(n + 1)]
p=2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 1
prime[0]= False
prime[1]= False
for p in range(n + 1):
if prime[p]:
print p,
3. Let m be the gcd of 117 and 299. Find m using the Euclidean algorithm (5 marks)
Answer.
299 = 117.2 + 65
117 = 65.1 + 52
65 = 52.1 + 13
52 = 13.4 + 0
Therefore the gcd of 117 and 299, m = 13
Answer.
def getgcd(a, b):
x=a
y=b
while y != 0:
r=x%y
x=y
y=r
return x
a = int(input("Enter the value of a: "))
b = int(input("Enter the value of b: "))
Answer.
def getgcdExtended(a, b):
if a == 0:
return b, 0, 1
gcd, x1,y1 = getgcdExtended(b % a, a)
x = y1 - (b//a) * x1
y = x1
return gcd, x, y
a = int(input("Enter the value of a: "))
b = int(input("Enter the value of b: "))
Answer.
Find the gcd of (71 and 1002)
1002 = 71.14 + 8
71 = 8.8 + 7
8 = 7.1 + 1
7 = 1.7 + 0
GCD = 1
Bezouts coefficients
1002Pp+71q = 1 7 = 71.1 – 8.8
8 = (1002 – 14(71)) 8 = 1002.1 – 71.14
7 = (71 – 8(8))
1 = (8 – 1(7))
Backward Substitution.
1 = (8 - 1(7))
1 =1.8 + -7.1
1 = 1.8 + -1(71.1 - 8.8)
1 = 1.8 – 71.1 + 8.8
1 = 9.8 – 71.1
1 = 9(1002.1 – 71.4) -71.1
1 = 1002.9 – 71.126 - 71.1
1 = 1002.9 – 71.127
1 = 1002(9) + 71(-127)
p =9, q = -127
Answer.
GCD
486 = 222.2 + 42
222 = 42.5 +12
42 = 12.3 + 6
12 = 6.2 + 0
Gcd =6
Bezouts coefficients
42 = (486 –2(222)) 42 = (486.1 – 222.2)
12 = (222 – 5(42)) 12 = (222.1 – 42.5)
6 = (42 – 3(12)) 6 = (42.1 - ) 12.3)
Backward substitution.
6 = 42 – 3(12)
6 = 42.1 – 12.3
6 = 1(486.1 -222.2) – 3(222.1 – 42.5)
6 = 486.1 – 222.2 – 222.3 + 42.15
6 = 486.1 -222.5 + 15(486.1 – 222.2)
6 = 486.1 -222.5 + 486.15 – 222.30
6 = 486.16 – 222.35
6 =486(16) + 222(-35)
x = 16
y = -35
Answer.
GCD
421 = 11.38 + 3
11 = 3.3 + 2
3 = 2.1 + 1
2 = 1.2 + 0
Bezouts coefficients.
3 = 421 – 38(11) 3 = 421.1 – 11.38
2 = 11 – 3(3) 2 = 11.1 – 3.3
1 = 3 – 2(1) 1= 3.1 – 1.2
Backward substitution.
1 = 3 – 2(1)
1 = 3.1 – 1.2
1 = 3.1 – 1(11.1 -3.3)
1 = 3.1 -11.1 + 3.3
1 = 3.4 – 11.1
1 =4(421.1 – 11.38) – 11.1
1 = 421.4 – 11.152 – 11.1
1 = 421.4 – 11.153
1 = 421(4) + 11(-153)
x=4 y = -153