I've just noticed that there is something on this algorithm in O'Reilly'sMastering Algorithms with Perl. (Miller-Rabin test, pgs 520-522). I don't actually have a copy of that book, but I am curious as to if it has an implementation, and if so then what differences there are with mine.