Skip to content

Instantly share code, notes, and snippets.

@slacktracer
Created May 31, 2017 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slacktracer/cc35323fa5b2b263524e8cbfa27a3c4a to your computer and use it in GitHub Desktop.
Save slacktracer/cc35323fa5b2b263524e8cbfa27a3c4a to your computer and use it in GitHub Desktop.
const makeG = n => x => (x ** 2 + 1) % n;
const gcd = (a, b) => (b === 0 ? a : gcd(b, a % b));
const pollard = n => {
const g = makeG(n);
let x = 1;
let y = 2;
let d = 1;
while (d === 1) {
x = g(x);
y = g(g(y));
d = gcd(Math.abs(x - y), n);
}
return d === n ? false : d;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment