Permalink
Browse files

Make prime_search run twice as fast by not testing even numbers.

  • Loading branch information...
1 parent 86c30f3 commit 61af560af0c1aa91a158ed10ba0e07bbf6a89476 Carl-Johan Kjellander committed Feb 26, 2011
Showing with 4 additions and 1 deletion.
  1. +4 −1 cth_rsa.erl
View
@@ -18,6 +18,7 @@
, fermat/1
, find_prime/1
, find_prime/2
+ , prime_search/2
, mod_inv/2
, n/2
, phi/2
@@ -153,10 +154,12 @@ find_prime(Bits, I) when Bits rem 8 =:= 0 ->
prime_search(_, 0) ->
{error, none_found};
+prime_search(N, I) when N rem 2 =:= 0 ->
+ prime_search(N+1, I);
prime_search(N, I) ->
case fermat(N) of
true -> N;
- _ -> prime_search(N+1, I-1)
+ _ -> prime_search(N+2, I-1)
end.
mod_inv(Phi, E) ->

0 comments on commit 61af560

Please sign in to comment.