Download RSA Encryption Project for CSC 222: Implementing Public-Key Cryptography Algorithm and more Study Guides, Projects, Research Computer Science in PDF only on Docsity! CSC 222: Programming Project # 1: RSA Encryption Instructor: V. Paúl Pauca due date: Thursday Oct. 9 (classtime) In this project we are going to implement the well-known RSA algorithm for public-key cryptography. The RSA algorithm is attributed to Ron Rivest, Adi Shamir and Leonard Adleman who first described in 1977. Algorithm. In public-key crytography each person has a public key known to everyone and a secret key known only to the person herself. Messages encrypted with a public key can only be decrypted using the corresponding private key. Thus if Taylor wants to send a message x to Lindsay, she encodes it using Lindsay’s public key. Lindsay decrypts it using her secret key, to retrieve x. The public and private keys for RSA encryption are generated by the following steps: 1. Choose two large and distinct (k-bit) random primes p and q. 2. Compute n = pq. 3. Compute the number s = (p− 1)(q − 1). 4. Choose an integer e such that 1 < e < s and e is relatively prime to s. 5. Compute d to satisfy the relationship de ≡ 1(mod s), that is, d is the inverse of e modulo s. Then the public and private keys are: • public key: (N, e) • private key: (N, d) To encrypt a message M, Taylor first turns it into a number m < n using some reversible protocol or padding scheme. She then computes c = me(mod n) and sends c to Lindsay. To decrypt the message, Lindsay computes m = cd(mod n), which can then be turned back into M using the padding scheme. Programming. You can choose either Java, C, or C++. In Java, class BigInteger provides the func- tionality to deal with large n-bit numbers. For C and C++, the GNU MP library for arbitrary precision arithmetic can be used. You may download and install the GMP library for Linux and Windows systems. Please refer to the course webpage for suggestions about installing GMP. You may also use rockola, one of the computing servers in our department. To do so, you will need to recall the username and password assigned to you by Paul Whitener, the system administrator. Consult me or Paul to learn how to access rockola. 1. (12 points) The main component of any RSA implementation is the generation of public and private keys. Let a, b, N denote k-bit numbers and define a class ModularArithmetic to contain the following static functions: • c = modadd(a, b, N) : returns c = a + b (mod N) • c = modmult(a, b, N): returns c = a ∗ b (mod N) • c = moddiv(a, b, N): returns c = a/b (mod N) • c = modexp(a, b, N): returns c = ab (mod N) • b = isPrime(N, k): returns true if N is prime with probability 1/2k, or false if N is not prime. • N = genPrime(n): returns a n-bit prime number N . CSC 222 Fall 2008 1