Name: Shirleen Chelangat Ruttoh. REG NO: SCT 212-0069/2018. Unit: Fundamentals of Computer Security Tech. Unit Code: BCT 2306. Assignment 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

NAME: SHIRLEEN CHELANGAT RUTTOH.

REG NO: SCT 212-0069/2018.


UNIT: FUNDAMENTALS OF COMPUTER SECURITY TECH.
UNIT CODE: BCT 2306.
ASSIGNMENT 1.
1. Using the theorem divisibility, prove the following
a) If |b , then |bc ( 5 marks)

Since a|b, then there exists m ꞓ Z st b = am


To show that a|bc,
bc = am(c), by Associativity,
bc = am(c) = a(mc), ie bc = a(mc)
by Closure Property of Multiplication,
mc = q ꞓ Z ,
Hence bc = aq ie
a|bc

b) If |b and |c , then | (5 marks)

Since a|b, then there exists y ꞓ Z st b = ay


a|c = m , c = am
b|c , then there exists k ꞓ Z st c =bk
b = ay ….. c = bk
c = ay(k)
c = a(yk)…… yk ꞓ Z
therefore
a|c

2. Using any programming language of choice (preferably python), implement the


following algorithms
a) Modular exponentiation algorithm (10 marks)

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

4. Write a program that implements the Euclidean Algorithm (10 marks)

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: "))

print("GCD(", a, ",", b, ") = ", getgcd(a, b))


5. Modify the Euclidean Algorithm above such that it not only returns the gcd of a and
b but also the Bezouts coefficients x and y, such that (10 marks)

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: "))

print("GCD(", a, ",", b, ") = ", getgcdExtended(a, b))

6. Find the integers p and q , solution to (5 marks)

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

7. Determine whether the equation has a solution such that

If yes, find x and y. If not, explain your answer. (5 marks)

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

8. Determine integers x and y such that . (5 marks)

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

You might also like