Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with python thanks! Finish implementing the code in practiceRSA.py and make sure you can encrypt and decrypt data. Encrypt a message with both

Need help with python thanks!
Finish implementing the code in practiceRSA.py and make sure you can encrypt and decrypt data. Encrypt a
message with both your pubic and private keys. Code for encrypting with a public key is given, do not forget to
provide code for private encryption. Include a screen shot of the output in your write up.
Part 2:
Given my public key(n,e), decrypt the cipher text C (represented as an integer) created with my public key :
C =395234002718058511371243487230167549851
public key =(902125837174791721758566383713256340347,65537)
Make a separate python file to calculate your solution to part 2. Explain what you did and how you cracked the public key
python code
cip#!/usr/bin/python3
from prime import *
import math
def main():
public,private = make_key(int(sys.argv[1]))
#public key =(n,e)
print(f"public key is ({public[0]},{public[1]})")
#private key =(n,d)
print(f"private key is ({private[0]},{private[1]})")
#message to encrypt
msg = b'test,message'
print (msg)
print(int.from_bytes(msg))
#cipher with public key
x = cipher(msg,public[1],public[0])
print(x)
#decipher with private key
y = dcipher(x, private[1], private[0])
print(y.to_bytes(len(msg)))
def cipher(m,e,n):
i = int.from_bytes(m)
return pow(i,e,n)
def dcipher(c,d,n):
#FINISH THIS FUNCTION
"""
FINISH THIS FUNCTION
You'll need a function from prime.py
"""
def make_key(bit_len):
#pick two prime numbers using bit_len
p1=
p2=
#compute n to be part of public key
n =
#l = lcm(prime1-1,prime2-1)
l =
#choose number 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions