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

SCT212-0047/2018

VICTOR KIMARU KIPLIMO


C.T 3.1
ASSIGNMENT 1
BCT 2306: FUNDAMENTALS OF COMPUTER SECURITY TECHNOLOGY

1. using the theorem divisibility, prove the following

a) If a|b , then a|bc ∀a,b,c∈ℤ ( 5 marks)

ak=b
bc=akc
Hence: a|bc

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

ak=b
bs=c
aks=c
Hence a|c

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

a) Modular exponentiation algorithm (10 marks)


a=2
b = 10
x = (int)(1e9+7)
d = pow(a, b) % x
print (d)

b) The sieve of Eratosthenes (10 marks)

def SieveOfEratosthenes(x):
      
    prime = [True for i in range(x + 1)]
    p = 2
    while (p * p <= x):
          
        if (prime[p] == True):
              
            for i in range(p * 2, x + 1, p):
                prime[i] = False

      p += 1
SCT212-0047/2018
VICTOR KIMARU KIPLIMO
C.T 3.1
ASSIGNMENT 1
BCT 2306: FUNDAMENTALS OF COMPUTER SECURITY TECHNOLOGY

    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)

299 = 117.2 + 65
117 = 65.1 + 52
65 = 52.1 + 13
52 = 13.4 + 0

=> 13

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

def euclid_algo(x, y, z=True):


if x < y: # We want x >= y
return euclid_algo(y, x, z)
print()
while y != 0:
if z: print('%s = %s * %s + %s' % (x, floor(x/y), y, x % y))
(x, y) = (y, x % y)

if z: print('gcd is %s' % x)
return x

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 𝑎𝑥+𝑏𝑦=1 (10 marks)

def gcdExtended(a, b):      


if a == 0 :
           return b,0,1  

 gcd,x1,y1 = gcdExtended(b%a, a) 

   x = y1 - (b//a) * x1 


   y = x1
 return gcd,x,y
SCT212-0047/2018
VICTOR KIMARU KIPLIMO
C.T 3.1
ASSIGNMENT 1
BCT 2306: FUNDAMENTALS OF COMPUTER SECURITY TECHNOLOGY

6. Find the integers p and q , solution to 1002𝑝 +71𝑞= 𝑚 (5 marks)

1002 = 71.14 + 8 8 = 1002.1 - 71.14

71 = 8.8 + 7 7 = 71.113 - 1002.8

8 = 7.1 +1 1 = 1002.9- 71.127

7 =1.7 +0 p=9

GCD = 1 q = -127

7. Determine whether the equation 486𝑥+222𝑦=6 has a solution such that 𝑥,𝑦∈𝑍𝑝 If yes, find x and
y. If not, explain your answer. (5 marks)

486 = 222.2 + 42 42 = 486.1 - 42

222 = 42.5 + 12 12 = 222.11 - 486.5

42 = 12.3 + 6 6 = 486.16 - 222.35

12 = 6.2 + 0 x = 16

GCD = 6 y = -35

8. Determine integers x and y such that 𝑔𝑐𝑑(421,11) = 421𝑥 + 11𝑦. (5 marks)

421 = 11.38 + 3 3 = 421.1 - 11.38

11 = 3.3 + 2 2 = 11.115 - 421.3

3 = 2.1 + 1 1 = 421.4 - 11.153

2 = 1. 2 + 0 x=4

GCD = 1 y = -153
SCT212-0047/2018
VICTOR KIMARU KIPLIMO
C.T 3.1
ASSIGNMENT 1
BCT 2306: FUNDAMENTALS OF COMPUTER SECURITY TECHNOLOGY

You might also like