Question

Problem 3 In RSA, we will consider what happens when Alice makes the mistake of choosing...

Problem 3
In RSA, we will consider what happens when Alice makes the mistake of choosing p,q
too close together. Her method is as follows. She chooses p
a random large prime, and then chooses q
to be the smallest prime greater than p
. You are Eve, and Alice's public key is (e,n)
where e=13
and n
is
4149515568880992958512407863691161151012446232242436899995657329690652811412991293413200434314186514261288537546721977134041420919065144782418033157091025480140853599374890776565691
(Make sure to copy all of n, which has 181
digits).


Find Alice's private key d

using python

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python code for finding the Alice's private key using p as a random prime number and q is the smallest prime which is greater than p.  

import random
def isPrime(n):
if n == 2 or n == 3: return True
if n < 2 or n%2 == 0: return False
if n < 9: return True
if n%3 == 0: return False
r = int(n**0.5)
f = 5
while f <= r:
if n%f == 0: return False
if n%(f+2) == 0: return False
f +=6
return True
primes = [i for i in range(1,1000) if isPrime(i)]
p = random.choice(primes)
primes2 = [i for i in range(p,2000) if isPrime(i)]
q = random.choice(primes2)
n=p*q;
print("n = p * q = " + str(n) + "\n")
phi=(p-1)*(q-1)
print("Euler's function Z)]: " + str(phi) + "\n")
def gcd(a, b):
while b != 0:
c = a % b
a = b
b = c
return a
def modinv(a, m):
for x in range(1, m):
if (a * x) % m == 1:
return x
return None
e=13
d=modinv(e,phi)
print("Your private key is (d=" + str(d))
def encrypt_block(m):
c = modinv(m**e, n)
if c == None: print('No modular multiplicative inverse for block ' + str(m) + '.')
return c
def decrypt_block(c):
m = modinv(c**d, n)
if m == None: print('No modular multiplicative inverse for block ' + str(c) + '.')
return m
def encrypt_string(s):
return ''.join([chr(encrypt_block(ord(x))) for x in list(s)])
def decrypt_string(s):
return ''.join([chr(decrypt_block(ord(x))) for x in list(s)])

Add a comment
Know the answer?
Add Answer to:
Problem 3 In RSA, we will consider what happens when Alice makes the mistake of choosing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Alice is a student in CSE20. Having learned about the RSA cryptosystem in class, she...

    2. Alice is a student in CSE20. Having learned about the RSA cryptosystem in class, she decides to set-up her own public key as follows. She chooses the primes p=563 and q = 383, so that the modulus is N = 21 5629. She also chooses the encryption key e-49. She posts the num- bers N = 215629 and e-49 to her website. Bob, who is in love with Alice, desires to send her messages every hour. To do so,...

  • O-8. (15 points) Bob's simple toy RSA eryptosystem has public key kyub(n, e) (65,5), where n =p,-...

    o-8. (15 points) Bob's simple toy RSA eryptosystem has public key kyub(n, e) (65,5), where n =p,-5x13-65 and e-5. I. Describe the key pair generation procedure for Bob to generate his private key kor- d. With the above given parameters, use EEA to calculate d 2. Describe RSA encryption procedure that Alice uses to encrypt her plaintext message x to its above given parameters, what will be y? ciphertext y before sending the message to Bob. Suppose Alice's message x-...

  • Consider the RSA algorithm. Let the two prime numbers, p=11 and q=41. You need to derive appropriate public key (e,n) and private key (d,n). Can we pick e=5? If yes, what will be the corresponding (d...

    Consider the RSA algorithm. Let the two prime numbers, p=11 and q=41. You need to derive appropriate public key (e,n) and private key (d,n). Can we pick e=5? If yes, what will be the corresponding (d,n)? Can we pick e=17? If yes, what will be the corresponding (d,n)? (Calculation Reference is given in appendix) Use e=17, how to encrypt the number 3? You do not need to provide the encrypted value.

  • Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA...

    Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA {    private BigInteger phi; private BigInteger e; private BigInteger d; private BigInteger num; public static void main(String[] args) {    Scanner keyboard = new Scanner(System.in); System.out.println("Enter the message you would like to encode, using any ASCII characters: "); String input = keyboard.nextLine(); int[] ASCIIvalues = new int[input.length()]; for (int i = 0; i < input.length(); i++) { ASCIIvalues[i] = input.charAt(i); } String ASCIInumbers...

  • This is the prompt then the question asks, "What is the ciphertext for the word LODE? (Simplify y...

    This is the prompt then the question asks, "What is the ciphertext for the word LODE? (Simplify your answers completely. Enter your answers as a comma-separated list.)" Please help I have been stuck for hours. In public key cryptography, there are two keys created, one for encoding a message (the public key) and one for decoding the message (the private key). One form of this scheme is known as RSA, from the first letters of the last names of Ron...

  • 11) a) Using RSA to encode with p-5,q-7 and c-7, what information do we make publicly...

    11) a) Using RSA to encode with p-5,q-7 and c-7, what information do we make publicly available? b) What is d, the private key? 12) Describe how, using RSA, Bob knows that, as claimed, it's really Alice sending the message. 13) Using non-randomized Select(A, n, i) to find the 4th largest element in array A, with A as I first pivot 8 11 14 09 4 25 33 98 5 22 63 54 2 111 45 23 19 728 16...

  • Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of...

    Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of physician-centered and collaborative communication. How is the caregiver’s role different in each model? How is the patient’s role different? Answer: Physical-centered communication involves the specialists taking control of the conversation. They decide on the topics of discussion and when to end the process. The patient responds to the issues raised by the caregiver and acts accordingly. On the other hand, Collaborative communication involves a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT