USING: math.miller-rabin kernel math math.functions namespaces sequences ; IN: crypto.rsa ! The private key is the only secret. ! p,q are two random primes of numbits/2 ! phi = (p-1)(q-1) ! modulus = p*q ! public = 65537 ! private = public modinv phi TUPLE: rsa modulus private-key public-key ; C: rsa : generate-rsa-keypair ( numbits -- ) modulus-phi public-key over mod-inv + public-key ; : rsa-encrypt ( message rsa -- encrypted ) [ rsa-public-key ] keep rsa-modulus ^mod ; : rsa-decrypt ( encrypted rsa -- message ) [ rsa-private-key ] keep rsa-modulus ^mod ;