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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 Algorithm
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
✓
>
Transcribed Image Text: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 ✓ >
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Binary numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education