aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-07-16 10:39:59 +0000
committerlloyd <[email protected]>2006-07-16 10:39:59 +0000
commit311b29d8115df01b4a7aa3d1207af3ae67afa7d1 (patch)
tree8c105219d5b00cae10091c63cd78ee4ebd084ad6
parent4232268d52018e14b9f32e0a3e3e9d657a0f8703 (diff)
Have to (potentially) factor the result from the Rho computation, as it
might be composite.
-rw-r--r--doc/examples/factor.cpp11
1 files changed, 7 insertions, 4 deletions
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<BigInt> remove_small_factors(BigInt& n)
std::vector<BigInt> factorize(const BigInt& n_in)
{
- BigInt n = n_in, a_factor = 0;
+ BigInt n = n_in;
std::vector<BigInt> factors = remove_small_factors(n);
while(n != 1)
@@ -96,11 +96,14 @@ std::vector<BigInt> 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<BigInt> 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;