Haskell RSA
About
RSA implementation in Haskell using https://en.wikipedia.org/wiki/RSA_(cryptosystem)
Example Results
Usage
λ> (public, private) = keygen Int Int
λ> encrypt public [Integral]
λ> decrypt private [Integral]
Key Generation
n is part of the public key and the private key e is part of the public key d is part of the private key
keygen returns a tuple formed by the public and private keys public = (n, e) private = (n, d)
- n is the product of two primes
- λ(n) is computed using Carmichael’s totient function but in this case since p and q are primes we can use the lcm formula
- e is computed such that λ(n) and e are coprime
- d is equal to the modular multiplicative inverse of λ(n)
Primes Generation
- Write down the list 2,3…
- Mark the first value as prime
- Remove multiples of p from the list
- Return to step 2