3.4k views
4 votes
Problem 4:

Implement the function encryptRSA(message, n, e) which encrypts a string message using RSA key (n = p * q, e). You may NOT use any built-in functions as part of your implementation, but you may use any functions you implemented for previous coding assignments. Please make sure to copy and paste them into this file, so that they are uploaded to CodePost when you submit your pa3.py file.

1 Answer

1 vote

Final answer:

To encrypt a string message using RSA key (n = p * q, e), you can follow these steps: convert each character in the message to its ASCII value, raise each ASCII value to the power of e modulo n, and convert the resulting values back to their corresponding characters and concatenate them to form the encrypted message.

Step-by-step explanation:

To encrypt a string message using RSA key (n = p * q, e), you can follow these steps:

  1. Convert each character in the message to its ASCII value, and store them in an array.
  2. Raise each ASCII value to the power of e modulo n.
  3. Convert the resulting values back to their corresponding characters and concatenate them to form the encrypted message.

Here's an example:

If the message is 'hello' and the RSA key is (n = 55, e = 3), then the ASCII values of 'h', 'e', 'l', and 'o' are 104, 101, 108, and 111 respectively. After raising each value to the power of 3 modulo 55, we get 24, 26, 37, and 1. Converting these values back to characters, we get 'x', 'z', '%', and '', and the encrypted message is 'xz%\u0001'.

User Max Droid
by
7.6k points