Let's say N = 2257. Let's trace through this example.
- Pick a random integer a, so that a < 2257. Our code picked a = 1344 in this example.
- Compute g = gcd(a,N) = gcd(1344,2257) = 1:
- Since g = 1, we have to keep going!
- Find the period of f(x) = ax (mod N) = 1344x (mod 2257). This period is r = 180:
- r is even, so we keep going!
- ar/2 = 1344180/2(mod 2257) = 1768 since; 1768 ≠ -1 (mod 2257) = 2256, we keep going!
- We've found two factors of 2257. They are gcd(ar/2 + 1, N) = gcd(1344180/2 + 12257) = 61 and gcd(ar/2 + 1, N) = gcd(1344180/2 - 12257) = 37.
Let's check our work: 61 * 37 = 2257. We got it right!