From UBC Wiki


Authors: Caleb Kellett, Heather DeHaven

What is the problem?

We will implement an RSA cryptosystem. The user will give two primes and a message to either encrypt or decrypt. Our program will find the needed integers for the rest of the public key and private key for decryption. It will successfully encrypt and decrypt messages with those keys. To do so, we will have to implement functions to find the greatest common divisor of two integers, check if integers are prime, and find an inverse modulo m.

What is the something extra?

We will be researching how RSA encryption works, and create our own implementation. We will also create an interface to store / receive keys and to input encrypted/unencrypted data. We will be evaluating how useful Haskell is for this purpose in regards to both the interface and the encryption.

What did we learn from doing this?

(This should be written after you have done the work.) What is the bottom-line? Is functional programming suitable for (part-of) the task? Make sure you include the evidence for your claims.

In our RSA Encryption implementation, we really made use of Haskell's list comprehensions for calculations like identifying if an integer is prime and generating the public and private keys, e and d, making what may be in other languages very large programs instead very compact. We also utilitized Haskell's map functions to map the message to numbers and apply the encryption function to each number and apply the decryption function to each number and map back to letters. Guards also allowed us to quickly and easily write our functions to map letters to numbers and numbers to letters; in other languages, we would have needed to use a switch.

For the UI, the IO makes it simple to organize and separate the sections of the program. Each step has it's own do block. If the user types in the incorrect input, the necessary do block calls itself to begin again, avoiding the user having to restart the entire program. However, the user needs to input Integers and lists of Integers for our program. The IO makes all inputs Strings. For each Integer and list of Integers, we needed to them to a Maybe Integer, check if they were all Justs (if there were Nothings, restart the do block), then cast to a Integer for our functions to use. Overall, the IO made the UI easy to organize and manage.

For these reasons, we found functional programming to be very suitable for an encryption type program.

Links to code