Task 1 RSA implementation (4%) By reference the code 'RSA_simple.py' to develop an RSA algorithm with Python, C++ or Jav
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Task 1 RSA implementation (4%) By reference the code 'RSA_simple.py' to develop an RSA algorithm with Python, C++ or Jav
Task 1 RSA implementation (4%) By reference the code 'RSA_simple.py' to develop an RSA algorithm with Python, C++ or Java that input a message and output the followings: - - The input plaintext P and Q value which are 5-digit prime NO The public key (e, n) and private key (d, n) The encrypted message (ciphertext) The decrypted plaintext
6 It is the number of positive integers less than n that are relatively prime to n. 7 Choose e, 1 <= e <= m - 1, such that gcd(e,m)=1. 8 Finds d such that ed=1 mod m. 9 This is possible because of the choice of e. 10 d is the multiplicative inverse of e modulo m and can be found using the Extended Euclidean algorithm. 11 Set public key to (e, n). 12 Set Private key to (d, n). 13 Encrypt: X^e mod n 14 Decrypt: Y^d mod n 15 16 17 import math 18 19 20 21 22 23 24 def encrypt (me): 25 # me^e mod n en = math.pow(me, e) c = en % n 35 36 26 27 28 29 30 31 def Decrypt(C): 32 L pass 33 34 37 38 111 39 40 41 42 43 #define method to find p, q and e # methods to display public and private keys 44 45 print("Encrypted Message is: ", c) return c # Main message = int(input("Enter the message to be encrypted: ")) #hard code P q and e p = 11 9 = 7 e = 3 n = p*q print("Original Message is: ", message) c = encrypt (message)