- 3rd Jul 2024
- 17:31 pm
In this assignment, you're going to encrypt small numbers... nothing big enough to be secure. Nor will you be doing any padding, etc. You can assume that any computations you have to do as part of the testing will fit into the machine's standard floating point size (In many languages, the data type 'double', short for 'double float').
- Problem 1 - For RSA, in real-world scenarios, we need to select two incredibly large random numbers. One way we can do this is by picking a random number, and then testing it for primality. In this exercise, we'll supply you with an array of integers that are all positive, and representable in 32 bits. For each integer, you will output a boolean value of true if it is prime, and false if it is not.
- Problem 2 - Now that we know how to test for primality, you could validate choices for p and q. But what you're really going to do is use it to, given values for p and q that are prime, find the lowest possible value of e.
- Problem 3 - Now we need to be able to compute d, by finding the modular inverse of e. Remember that the number we're looking for, when multiplied by e and reduced by1 LCM(p-1, q-1), will give the value 1.
- Problem 4 - Great, we're ready to encrypt. Raw encryption and decryption in RSA consist of a single exponentiation operation in our multiplicative group, so we've already done all the hard work.
- Problem 5 - Okay, now let's decrypt! We will give you the values of p and q to use. You will again select the smallest valid value of e. That way we'll already have your 'public' key. We'll also send you an encrypted number, y.
Understanding the RSA Math - Get Assignment Solution
Please note that this is a sample assignment solved by our Python Programmers. These solutions are intended to be used for research and reference purposes only. If you can learn any concepts by going through the reports and code, then our Python Tutors would be very happy.
- Option 1 - To download the complete solution along with Code, Report and screenshots - Please visit our Python Assignment Sample Solution page
- Option 2 - Reach out to our Python Tutors to get online tutoring related to this assignment and get your doubts cleared
- Option 3 - You can check the partial solution for this assignment in this blog below
Free Assignment Solution - Understanding the RSA Math
import math
import json
def isPrime(n):
for i in range(2, int(n**0.5)+1):
if n%i == 0:
return False
return True
def lcm_e(e,r):
while(r != 0):
e,r = r,e%r
return e
def extended_gcd(a,b):
if a%b == 0:
return (b,0,1)
else:
g, y, x = extended_gcd(b, a%b)
y = y - ((a//b)*x)
return (g, x, y)
def modinv_d(e,r):
g,x,y = extended_gcd(e,r)
if g != 1:
return None
else:
return x%r
def encrypt(e,n,x):
return (x**e) % n
def decrypt(p,q,y,e):
r = (p-1) * (q-1)
d = modinv_d(e,r)
n = p*q
return (y**d) % n
f = open('example-input_json.txt')
data = json.load(f)
nums = data['problem 1']['nums']
prob1 = []
for x in nums:
flag = isPrime(x)
prob1.append(flag)
prob2_p = data['problem 2']['p']
prob2_q = data['problem 2']['q']
r = (prob2_p-1) * (prob2_q-1)
for i in range(2, 1000):
if lcm_e(i,r) == 1:
prob2_e = i
break
prob3_p = data['problem 3']['p']
prob3_q = data['problem 3']['q']
r2 = (prob3_p-1) * (prob3_q-1)
for i in range(2, 1000):
if lcm_e(i,r2) == 1:
prob3_e = i
break
d = modinv_d(prob3_e, r2)
prob4_e = data['problem 4']['e']
n = data['problem 4']['n']
x = data['problem 4']['x']
enc = encrypt(prob4_e,n,x)
prob5_p = data['problem 5']['p']
prob5_q = data['problem 5']['q']
y = data['problem 5']['y']
r3 = (prob5_p-1) * (prob5_q-1)
for i in range(2, 1000):
if lcm_e(i,r2) == 1:
prob5_e = i
break
dec = decrypt(prob5_p, prob5_q, y,prob5_e)
output = {}
output['problem 1'] = prob1
output['problem 2'] = prob2_e
output['problem 3'] = d
output['problem 4'] = enc
output['problem 5'] = dec
with open("output_json.txt", "w") as out:
json.dump(output, out)
Get the best RSA Math assignment help and tutoring services from our experts now!
About The Author - Dr. Alex Johnson
Dr. Alex Johnson is a distinguished professor of Computer Science with a specialization in cryptography and information security. With a PhD from Stanford University, Dr. Johnson has dedicated over two decades to researching and teaching encryption techniques, including RSA. He has authored several influential papers and books on cryptography, making complex mathematical concepts more accessible to students and professionals.