A Programmer Solved a 20-Year-Old, Forgotten Crypto Puzzle

Here's an example; not exactly how it's done, but maybe it helps:

You have 2 huge primes, p and q. Call their product n.

Now I pick an arbitrary modulo m.

The only (known) algorithm (in this hypothetical scenario) to calculate 2^n mod m takes n steps.

However, because of the properties of the modulo, I can instead calculate (2^p mod m) * (2^q mod m) mod m. So instead of taking p*q time I'm only taking p+q time.

So imagine I take 1ms for each "power" (i.e., 21 takes 1ms, 2100 takes 100ms). Then, if p and q are 9 digits long, it'd take me 1010 + 1010 to calculate that number, which comes up to ~200 days. However, if you don't know p and q, you need to calculate it the long way around (or factor the prime, which is in itself a similarly long task). In that case it'd take you 1020 milliseconds which is more than a billion years.

Again, this is not exactly a representation of what's actually going on in the puzzle, it's just a simplification meant to show how the fact that the creator knows the factors of n allows him to use properties of the powers over modulo to save a lot of time.

/r/programming Thread Parent Link - ired.com