General Setting
You have learned in the lectures how the RSA protocol works. Here, you are going to implement RSA at a rather small scale. What is expected from you is to write your code in such a way that it can efficiently work with prime numbers less than 10000. You can find a list of the first 1000 prime numbers at http://primes.utm.edu/lists/small/1000.txt to check your codes. It would be, of course, better if your codes can handle larger numbers as well, but it is not required at this stage.
You are going to write several MATLAB functions (m files) corresponding to different tasks required in the RSA protocol. The first task is to create public and private keys, i.e., to generate parameters N = p x q, d,
and e, as will be explained later. The second task is that, given the public key, you write a function that encrypts a given message. Similarly, given the private key, you should write a function that decrypts a ciphertext. Finally, you should write a code that hacks your RSA implementation, that is, by getting the ciphertext and the public key, it will find the original plaintext. Here, I describe each of these tasks in more detail.
Task 1: Generating Public and Private Keys [4 pointsi]
You are expected to write a function RSA_Gen.m that accepts two prime numbers p and q at its input, and gives us three integer numbers N, d, and e at its output:
function (N, d, e) = RSA_Gen (p,q);
For N = p x q and z = (p-1) (q-1), d and e must satisfy the following conditions:
1. e < N 2. e and z have no common factors, that is, if you factor z into its prime-number constituents, e would not be divisible by any of those prime numbers. Equivalently, the greatest common divisor of e and z must be one. 3. Choose d such that ed 1 is divisible by z, that is, ed = 1 mod z. Your public key is then given by the pair (N,e), and your private key is given by (N,d). These MATLAB functions may help you in this project: rem, mod, gcd, and factor. Make yourself familiar with them and their limitations. Do they correctly do their job for very large numbers?Task 2: RSA Encryption [4 points] You are expected to write a function RSA_Enc.m that accepts the public key (N,e) along with a message m (a natural number less than N) at its input, and gives us the encrypted version of m at its output: function c = RSA_Enc (N,e,m); You basically need to write a code that calculates c = me mod N. If m or e are large numbers, you may need to calculate c in multiple steps; remember the limitations of the MATLAB functions that you use and that (a x b) mod N = (a mod N) x (b mod N).Task 3: RSA Decryption [2 points] You are expected to write a function RSA_Dec.m that accepts the private key (N,d) along with a ciphertext c (a natural number less than N) at its input, and gives us the plaintext m at its output: function m = RSA_Dec (N,d,c); You basically need to write a code that calculates m = cd mod N. Again, If c or d are large numbers, you may need to calculate m in multiple steps; remember the limitations of the MATLAB functions that you use and that (a x b) mod N = (a mod N) x (b mod N).Task 4: Hacking RSA [3 points] You are expected to write a function RSA_Hack.m that accepts the public key (N,e) along with a ciphertext c (a natural number less than N) at its input, and gives us the plaintext m at its output: function m = RSA_Hack (N,e,c); Make the assumption that N < 108.
Reviews
There are no reviews yet.