Fermat and Solovay-Strassen primality testing in Scheme
Following up on my implementation of RSA in Scheme, I created an implementation of the probabilistic Fermat and Solovay-Strassen primality tests for the purpose of large prime generation. The code allows both the byte-size of the prime and the confidence that the result is a prime to be chosen.
Once again, Scheme was a beautiful language for describing these algorithms.
This is part of my ongoing effort to create benchmarks for Scheme that exercise only a small part of the language, yet do serious computation.
Warning: If you want to use this in practice, you'll also have to add a weak-key detection pass to make it reasonably secure.