From 311b29d8115df01b4a7aa3d1207af3ae67afa7d1 Mon Sep 17 00:00:00 2001 From: lloyd Date: Sun, 16 Jul 2006 10:39:59 +0000 Subject: Have to (potentially) factor the result from the Rho computation, as it might be composite. --- doc/examples/factor.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'doc') diff --git a/doc/examples/factor.cpp b/doc/examples/factor.cpp index 93a7a0e9e..163d83fe0 100644 --- a/doc/examples/factor.cpp +++ b/doc/examples/factor.cpp @@ -85,7 +85,7 @@ std::vector remove_small_factors(BigInt& n) std::vector factorize(const BigInt& n_in) { - BigInt n = n_in, a_factor = 0; + BigInt n = n_in; std::vector factors = remove_small_factors(n); while(n != 1) @@ -96,11 +96,14 @@ std::vector factorize(const BigInt& n_in) break; } - do + BigInt a_factor = 0; + while(a_factor == 0) a_factor = rho(n); - while(a_factor == 0); - factors.push_back(a_factor); + std::vector rho_factored = factorize(a_factor); + for(u32bit j = 0; j != rho_factored.size(); j++) + factors.push_back(rho_factored[j]); + n /= a_factor; } return factors; -- cgit v1.2.3