; Use http://cap-lore.com/code/mult/ff.txt for mod-exp and to find primes. ; Use http://cap-lore.com/code/Scheme/eea (define (inv a p) (mod-exp a (- p 2) p)) (define (mrg p q) (let ((P (* p (inv p q)))(Q (* q (inv q p)))(pq (* p q))) (lambda(a b) (modulo (+ (* b P)(* a Q)) pq)))) ; RSA below returns a public-private pair of routines given two primes each not 1 mod 17. (define (RSA p q) (let ((pq (* p q)) (e 17) (mg (mrg p q)) (em (* (- p 1)(- q 1)))) (if (> (gcd e em) 1) "Bad" (let* ((d (modulo (car (eea e em)) em)) (pe (modulo d (- p 1)))(qe (modulo d (- q 1)))) (cons (lambda (p) (mod-exp p e pq)) (lambda (c) (mg (mod-exp (modulo c p) pe p) (mod-exp (modulo c q) qe q)))))))) ; The Java code at http://www.cs.utsa.edu/~wagner/laws/ARSAFast.html seems to use this logic. ; I coded this in 2006 before I saw Wagner's earlier code.