Skip to content

Instantly share code, notes, and snippets.

@ikr7
Created May 1, 2016 06:04
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 ikr7/8036cafbd3c84c64b81be1ad4b5ce0a0 to your computer and use it in GitHub Desktop.
Save ikr7/8036cafbd3c84c64b81be1ad4b5ce0a0 to your computer and use it in GitHub Desktop.
ポラード・ロー素因数分解アルゴリズム
'use strict';
const xor64 = function (y) {
y = y >>> 0;
y = y ^ (y << 13);
y = y ^ (y >> 7);
y = y ^ (y << 17);
return y >>> 0;
};
const GCD = function(m, n) {
while (n != 0) {
[m, n] = [n, m % n];
}
return m;
}
const factorize = function (n) {
const f = function (seed) {
return xor64(seed) % n;
}
let x = 2;
let y = 2;
let d = 1;
while (d == 1) {
x = f(x);
y = f(f(y));
d = GCD(Math.abs(x - y), n);
}
if (d == n) {
return false;
}
return d;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment