Unformatted text preview:

CMSC 222 Project 2: RSA 1CMSC 222 Project 2: RSADue Date: 11:59pm, Fri. Oct 19Overview:In this project, you will write code to implement the RSA public key cryptographic algo-rithm, and you will perform experiments using this algorithm.Project Description:The RSA (Rivest, Shamir, Adleman) public key cryptographic algorithm performs encryption as well as decryption. RSA works by use of two keys --- a public key and a pri-vate key. Using your public key, anyone can encrypt a message and send it to you. In the event that an adversary intercepts the encrypted message, she cannot decipher the message unless she knows your private key (reverse engineering with the public key will not work here). Encryption and decryption under RSA are based on modular exponentiation using large prime numbers, as described next.To generate a public key, choose two large prime numbers p and q (in practice, these are typically around 256 bits each) and let n = pq. Then choose a number e that is relatively prime to (p-1)(q-1). The public key is <e,n>. To encrypt her plaintext message (or at least a portion thereof) represented as an integer M (you must have M < n), your friend Alice can compute the ciphertext C = Me mod n. Only you will be able to decrypt C using your private key.To generate a private key, find the unique number d that is the multiplicative inverse of e modulo (p-1)(q-1) – this process involves the Euclidean algorithm and was discussed in class. The private key is <d,n>. You can then compute the original message (or portion thereof) M = Cd mod n using Alice’s encrypted message C.Unless you do something silly (like give away your private key), RSA is by current stan-dards a very secure means of encrypting information. More specifically, we have no guar-antee that RSA is in fact secure. We can only trust that many smart people have been attempting to break RSA, but they have been unsuccessful because factoring a large num-ber is hard1 (Remember that we choose n = pq where p and q are large primes, so unless the adversary can factor n, she cannot determine the exponent d that will allow her to decrypt messages.)So how do we choose large primes p and q? We could try the Sieve of Eratosthenes, but for very large primes this will be extremely inefficient (in fact, prohibitively so). The method usually used is beyond the scope of this project, but it will suffice to say that we choose a large number and then test its primality probabilistically. If the number chosen passes the test, with very high probability the number will actually be prime and therefore 1. We do not know that factoring n is the only way to break RSA, but we do know that breaking RSA is no more difficult than factoring.CMSC 222 Project 2: RSA 2RSA will work.It should be noted that in practice public key cryptography is not typically used to encode and decode entire messages. Instead, public key cryptography is often used to send a pri-vate key so that parties can then communicate using private key cryptography, which is in general less computationally intensive. Nonetheless, we will use RSA public key cryptog-raphy to encode and decode messages for this project – a great application of using the Euclidean algorithm and prime number and modular arithmetic concepts presented in class.Specifications:1. You must must implement your code in Java.2. You must produce three separate executables: rsaEncrypt, rsaDecrypt, and gcd.3. rsaEncrypt must accept as command line arguments:3.1. an input string, delimited by double quotation marks, of ASCII characters to be encoded;3.2. a public key exponent e;3.3. and a large number n (for this project, but not in practice, it will suffice to store n as a long).4. rsaDecrypt must accept as command line arguments:4.1. an input string of digits (the output from rsaEncrypt, for example);4.2. a private key exponent d;4.3. and a large number n.5. gcd must accept as command line arguments two integers on which to perform the Euclidean algorithm as discussed in class.Encrypting:Your program rsaEncrypt must perform the RSA encryption algorithm on the provided input string of ASCII characters using the given public key <e,n> where n = pq. More specifically: 1. Represent each character in the input string by its 3-digit ASCII numeric equivalent (e.g., ‘!’ is 033, ‘C’ is 067, ‘z’ is 122) – cast the char to an int.2. Break the resulting sequence of numbers into blocks of 8 – each block will comprise the M in the C = Me mod n operation. (We will use blocks of 8 for this project because the values of n that we will use will be 9 digits long. Remember from above that we must have M < n.) If the final block is fewer than 8 digits, pad to the right with sufficient zeros. Note that it is easier to pick out digits if your 8 digit blocks are actually stored as Strings of digits rather than longs. You can convert back to numeric type using Long.parseLong before doing the modular exponentiation.CMSC 222 Project 2: RSA 33. For each block of 8 digits, perform the encryption algorithm on that block. The result will be a number less than n. If the number is less than 9 digits (the length of n for this project), pad to the left with sufficient zeros.4. Concatenate all the 9-digit encrypted results and output the entire string.Your program must produce output similar to the following: % java rsaEncrypt “CMSC 222” 13 100160063 032059734076216682096586161The above example uses e = 13 and n = 100,160,063 (i.e., p = 10,007 and q = 10,009). Note that gcd(13, 100,140,048) = 1 where (p-1)(q-1) = 100,140,048, i.e., e and (p-1)(q-1) are relatively prime.Decrypting:Your program rsaDecrypt must perform the RSA decryption algorithm on the provided input string of digits using the given private key <d,n> where n = pq. More specifically, reverse the process from above:1. Break the input string of digits into blocks of 9, and perform thedecryption algorithm on each block using M = Cd mod n.2. If the result M is less than 8 digits, pad to the left with sufficient zeros.3. Concatenate all the 8-digit decrypted numbers.4. Break this long string of numbers into blocks of three. Convert each 3-digit numeric equivalent to the corresponding ASCII character – cast the int to a char. Remem-ber that in the encryption process, the final 8-digit block may have been padded with zeros to the right – do the appropriate thing here.5. Concatenate all the decrypted characters and output the entire string, delimited


View Full Document

U of R CMSC 222 - Project 2

Documents in this Course
Load more
Download Project 2
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Project 2 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Project 2 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?