THIS IS NOT MEANT TO BE USED FOR CRYPTOGRAPHIC PURPOSES. This implementation is naive and only for educational purposes. It does not consider defend against these attacks. Note that RSA scales badly, and ECC should be used instead.
This is a toy implementation of RSA and ECC. RSA keys are generated using a file containing large prime numbers. Basic number theory functions are defined in another module called NumberTheory
, which is imported by RSA
.
To use, import RSA
. Then, encrypting the number 0123456789
and decrypting it again can be done using the following.
import RSA
main = do
let plainText = 123456789
primesList <- loadPrimeNumbers -- load list of primes
(private, public) <- generateRSAKey primesList -- generate keys
let cipherText = encryptRSA plainText public -- encrypt
decipheredText = decryptRSA cipherText private -- decrypt
putStrLn $ show plainText
putStrLn $ show cipherText
putStrLn $ show decipheredText
One possible output is
123456789
28716360466573212816140507227160896071254936916916992565701437712147840827172086840295534503452291831112126708177551905202700662825376899309838765076207820678592014757269191144865356746643576321071055950922765550493050235392521781774700826
123456789
- Arbitrarily large integers supported natively
- Very safe system, pure and impure functions very clearly seperated