Let's say N = 837. Let's trace through this example:
- Pick a random integer a, so that a < 837. Our code picked 802 in this example.
- Compute g = gcd(a,N) = gcd(802,837) = 1:
- Since g = 1, we have to keep going!
- Find the period of f(x) = ax (mod N) = 802x (mod 837). This period is r = 30:
- r = 30 is even, so we keep going!
- ar/2 = 80230/2(mod 837) = 433 and 433 ≠ -1 (mod 837) = 836, so we keep going!
- We've found two factors of 837. They are gcd(ar/2 + 1, N) = gcd(80230/2 + 1837) = 31 and gcd(ar/2 + 1, N) = gcd(80230/2 - 1837) = 27.
Let's check our work: 31 * 27 = 837. We got it right! Note that since one number isn't prime, there are a variety of different pairs of numbers that factor 837. The algorithm will always produce a valid pair, but which pair depends on the sequence of random numbers that have been chosen, so the algorithm may show can generically different results.