8
$\begingroup$

I have two numbers, which are each the product of a large number of smaller numbers that I know. I want to find the GCD (Greatest common divisor) of these two numbers. Is there any way I can make use of the partial factorization I have to speed up the process?

In particular, each larger number is the product of $2^{15}$ smaller numbers, each of which is on the order of $2^{4000}$. I don't know anything about the factorization of the smaller numbers.

Edit: While the input numbers are about 120,000,000 bits, the GCD is about 500,000 bits. The factors of the numbers are in particular in sequence. They are all integers in a consecutive range.

All of the GCD algorithms I've seen make use of the numbers directly, not in a partially factored form or anything. Are there any algorithms which could incorporate this information to speed things up?

$\endgroup$
1
$\begingroup$

You can compute the pairwise GCDs of the factors. You have to divide out the GCDs from the factors to avoid finding the same GCD factor twice:

a[1...m] = [given factors of A]
b[1...n] = [given factors of B]
g = 1
for i from 1 to m do
    c = a[i]
    for j from 1 to n do
        d = gcd(c, b[j])
        g = g * d
        c = a[i] / d
        b[j] = b[j] / d
return g

Unfortunately, I don't think that this is not notably faster than the computation of the GCD of the two numbers A and B.

$\endgroup$
0
$\begingroup$

There was a similar problem that has been solved reasonably efficiently: Assume you are using RSA which is all built on products of two large primes, where the products can't be factored in reasonably time. But if you have two products pq and p'q' and either p=p' or q=q' then you can calculated their gcd and get p=p' or q=q' and the other factor is trivial. Of course if p=p' and also q=q' then this is no help.

No imagine someone generates a billion such products and is a bit careless. A hacker finds that quite a few numbers are identical, so p=p' and q=q', so it's a good guess that quite a few pairs have a gcd ≠ 1. And that has happened in real life with routers whose encryption could be cracked as a result.

Sorry, I don't have any reference and the story is a bit old, but you should be able to find it. Was a few years ago, maybe six or so.

$\endgroup$
  • $\begingroup$ Unfortunately, none of the factors of the two numbers are equal, so I can't strip them out that way. $\endgroup$ – isaacg Jun 1 '17 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.