In your favorite language (preferable in Python) create the following functions: 1. MRT →Use Miller-Rabin Primality Test to choose prime number with s=512 bits and check the primality test.
i dont know what im missing, project is due in a couple of hours and my output is just a blinking cursor. please help me. below is my source code and attatched is my project. please please help!
source code:
import random
def powMod_sm(base, exp, n):
exp_b=bin(exp)
value=base
for i in range(3, len(exp_b)):
value=(value**2)%n
if exp_b[i:i+1]=='1: ':
value = (value * base)% n
return value
# using the euclidean
def computeGCD(x, y):
while y:
x, y = y, x % y
return x
#Extended euclidean Algorithm method to calculate gcd and get the coefficient
def extendedGCD(a, b):
if a == 0:
return b, 0, 1
gcd, x1, y1 = extendedGCD(b % a, a)
x = y1 - (b // a)* x1
y = x1
return gcd, x, y
# calculating the modular inverse using EEA
def mod_Inv(b, n):
gcd, _, t = extendedGCD(n, b)
if gcd==1:
i = t % n
elif gcd!=1:
print("Inverse is undefined")
return i
#miller-rabin Primality test
def mrt(p):
if p == 2 or p == 3:
return True
if p<=1 or p%2==0:
return False
p1=p-1
t=15
u=0
r=p1
while r%2==0:
u=u+1
r=r/2
for i in range (1,t):
a=random.randint(2,p-2)
z=powMod_sm(a, int(r), p)
if z!=1 and z!=p1:
j=1
while j<u and z!=p1:
z=powMod_sm(z, 2, p)
if z==1:
return False
j+=1
if z!=p1:
return False
return True
# generating a random prime number given the bit length
def gen_prime(len):
n=random.getrandbits(len)
n|=(1<<len-1)|1
while not mrt(n):
n=random.getrandbits(len)
n|=(1<< len - 1)|1
return n
# using the random prime number generated above
# i will create a public and private rsa key
def rsa_key(p,q):
n=p*q
phi_n=(p-1) * (q-1)
for i in range (2,124):
if computeGCD(i, phi_n)==1:
e=i
break
d=mod_Inv(e,phi_n)
return n,e,d
# running main function and generating two prime number that are not =
def main():
p=gen_prime(60)
q=gen_prime(60)
while p==q:
q=gen_prime(60)
print ("prime number 1 is: ", p)
print ("prime number 2 is: ", q)
#generating private and public key
n,e,d=rsa_key(p,q)
print("public key is : ")
print("exponant e: ",e)
print("n : ", n )
print("private key is : ")
print("exponant d: ", d)
print("n : ", n)
#message to encrypt:
m= 8675390
print("The original message: ", m)
# encrypt using the powMod_sm method:
y=int(powMod_sm(m, e, n))
print("the encrypted message is: ", y)
#now decrypt the encrypted message using powMod_sm:
x=int(powMod_sm(y, int(d), n))
print("The original method after decryption: ", x)
main()
![Bb Project3_RSA.pdf
C
1 of 1
Type here to search
X C Post a new question
Online Python Compiler - onli
O8 https://learn-us-east-1-prod-fleet02-xythos.content.blackboardcdn.com/61aab133e7df2/61828331?X-Blackboard-Expiration=1
- + Automatic Zoom
II.
Online Python Compiler - online editor
In your favorite language (preferable in Python) create the following functions:
1. MRT →Use Miller-Rabin Primality Test to choose prime number with s=512 bits and
check the primality test.
EA Use Euclidean Algorithm to evaluate ged
III.
Project 3 on RSA:
2.
3. EEA →Use Extended Euclidean Algorithm to find modular inverse of the value
4. powmod_sm➜ Square and multiply algorithm to evaluate exponentiation.
Now write the code for
I. RSA Key Generation (use above functions 1., 2., 3.) should be
a. Choose two primes p and q of s bits using MRT where p is not equal to q.
b. Calculate n = p * q, and (n) (p − 1) * (q − 1)
=
c.
Chose randomly e from the set of {1,..., (n)-1} and check using EA if
gcd(e,p(n)) = 1 if not chose again until it full fills the condition.
d. Calculate d = e¯¹ mod $(n) using EEA. Note that d should be at least 0.3 * s
bits
e. Output kpub = (n, e) and kpr
(d)
RSA Encryption with input Kpub = (n, e) and random plaintext x and output should be
ciphertext y, evaluate exponentiation using the function powmod_sm
=
RSA Decryption with input kpr = (d) and ciphertext y and output should be plaintext.x,
evaluate exponentiation using the function powmod_sm. Please make sure to check that
you get the same plaintext value before the encryption.
Please write your report and include snapshot of output with you source code.
22.04
Earn... A
(8)
<
(4)
|
→
0
I 2
8:34 PM
12/20/2022
X
✓
>](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe6fd9b70-2e70-4e89-933a-53212f905e1a%2Fb5d7ccd3-adc5-4575-b59a-8eedc0aed29a%2Fi9knkuv_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)