Ulf =?iso-8859-1?Q?M=F6ller?= (ulf@fitug.de)
Tue, 24 Mar 98 00:40 CET
>BTW, I will point out that a version of RSA in Scheme is only a few
>lines longer, and actually can be read and understood easily by people
>(which might make it of more use in a legal context.)
Here is my version again:
(define(RSA m e n)(list->string(u(r(s(string->list m))e n))))(define(u a)(if(>
a 0)(cons(integer->char(modulo a 256))(u(quotient a 256)))'()))(define(s a)(if
(null? a)0(+(char->integer(car a))(* 256(s(cdr a))))))(define(r a x n)(cond((=
0 x)1)((odd? x)(modulo(* a(r a(- x 1)n))n))(#t(modulo(expt(r a(/ x 2)n)2)n))))
The actual computation takes less than 1.5 lines. The following
function is equivalent to it, but optimized for readability instead
of size:
(define (modexpt a x n)
(cond ((zero? x) 1)
((even? x) (modulo (expt (modexpt a (/ x 2) n) 2) n))
(else (modulo (* a (modexpt a (- x 1) n)) n))))
Here's how to use it:
(define c (RSA "The magic words are squeamish ossifrage" 5 114381625757888867669235779976146612010218296721242362562561842935706935245733897830597123563958705058989075147599290026879543541))
(display (RSA c 45752650303155547067694311990458644804087318688496945025024737159778909096647814932594914301288138204957467016445183857236173773 114381625757888867669235779976146612010218296721242362562561842935706935245733897830597123563958705058989075147599290026879543541))
More crypto (including RSA key generation) in Scheme is at
http://www.fitug.de/ulf/crypto/scheme.html
The following archive was created by hippie-mail 7.98617-22 on Fri Aug 21 1998 - 17:16:11 ADT