public int?PollardParallel(long _g, long _a, long _m, long _n) { Random rand = new Random(); int length = 100; var lpows = new List <int>(); var rpows = new List <int>(); var ai = new List <int>(); var bi = new List <int>(); var si = new List <int>(); var ti = new List <int>(); var result = new List <int>(); for (int i = 0; i < length; i++) { ai.Add(rand.Next(0, (int)(_n - 1))); bi.Add(rand.Next(0, (int)(_n - 1))); lpows.Add((int)((CryptographyMath.FastPower(_g, ai[i], _n) * CryptographyMath.FastPower(_a, bi[i], _n)) % _n)); } si.Add(rand.Next(0, (int)(_n - 1))); ti.Add(rand.Next(0, (int)(_n - 1))); rpows.Add((int)(CryptographyMath.FastPower(_g, si[0], _n) * CryptographyMath.FastPower(_a, ti[0], _n) % _n)); LogWithoutDate("\ti\tgi\tai\tbi\tsi\tti"); LogWithoutDate("\t" + 0 + "\t" + rpows[0] + "\t" + ai[0] + "\t" + bi[0] + "\t" + si[0] + "\t" + ti[0]); for (int i = 0; i < rpows.Count; i++) { int index = EasyCalculatableFunction((int)_m, rpows[i], rpows.Count) - 1; rpows.Add((int)((rpows[i] * lpows[index]) % _n)); si.Add((int)((si[i] + ai[index]) % _n)); ti.Add((int)((ti[i] + bi[index]) % _n)); LogWithoutDate("\t" + (i + 1) + "\t" + rpows[i + 1] + "\t" + ai[index] + "\t" + bi[index] + "\t" + si[i + 1] + "\t" + ti[i + 1]); for (int j = 0; j < rpows.Count; j++) { for (int k = 0; k < rpows.Count; k++) { if (rpows[k] == rpows[j] && j != k) { if (si[k] != si[j]) { long x = Math.Abs(si[k] - si[j]) * CryptographyMath.FastPower(Math.Abs(ti[j] - ti[k]), CryptographyMath.Euler(_a) - 1, _a); x = x % _m; if (_a == CryptographyMath.FastPower(_g, x, _m)) { return((int)x); } } } } } } return(null); }
public int AutoFindN(long _g, long _m) { int i = 1; var lst = new List <long>(); long res = CryptographyMath.FastPower(_g, i, _m); while (res != 1) { if (lst.Contains(res)) { Log("Не выйдет найти х - плохой диапазон значений. Попробуйте выбрать другие значения!"); return(-1); } else { lst.Add(res); i++; res = CryptographyMath.FastPower(_g, i, _m); } } return(i); }