Hi.<br>
<br>
I need some help here. I'm new to Scheme and now I'm supposed to build a RSA encryption algorithm.<br><br>I have some guidelines to build it and I'll post them now.<br><br>1. Write a procedure "prime?" that given a natural (positive) number returns true if that number is a prime number or false otherwise.
<br><br>2. Write a procedure "calc-e" that receives an argument n and returns a natural number, between 1 and n, that is a coprime of n.<br><br>3. Write a procedure "calc-d" that given 2 arguments, e and n, returns a natural number d, such that there is a number k to which the following expression is true:
<br><br>d . e = 1 + k . n<br><br>4. Write a procedure "RSA" that receives 2 natural (positive) numbers, k and l, and generates a public key and it's respective private key that uses de k-th and the l-th prime numbers as the initial prime numbers. The keys should be displayed in the screen in an adequate form
<br><br>5. Write a procedure "encoder" that receives 2 natural numbers that correspond to the public and private key and returns a procedure that the argument is de encoder or decoder that uses the received key.
<br><br>I'm not able to use every primitive procedure in Scheme. I'm only able to use these procedures:<br><br>Numerical operations;<br>Predicates;<br>Logical operations;<br>abs, cond, else, if, lambda, let, let*;
<br>begin, display, newline;<br><br>I guess that's all of them...<br><br>So far I have this:<br><br>;Begin prime?<br><br>(define (prime? k)<br> (if (<= k 1)<br> "Error: Insert number over 1."<br> (= k (smallest-divisor k))))
<br><br>(define (smallest-divisor k)<br> (divisor k 2))<br><br>(define (divisor k test-divisor)<br> (cond ((< k (sqrt test-divisor)) k)<br> (( divisor? test-divisor k) test-divisor)<br> (else (divisor k (+ test-divisor 1)))))
<br><br>(define (divisor? a b)<br> (= (remainder b a) 0))<br><br>;End prime?<br><br>;Begin calc-e<br><br>(define (a n)<br> (gcd (- n 1) n))<br><br>(define (calc-e n)<br> (if (= (a n) 1)<br> (- n 1)<br> (a ( - n 1))))
<br><br>;End calc-e<br><br>If there's anyone that could help me out here I would appreciate it.<br><br>Regards.<br>