def test(a, p, target): E.params(a, -a, p) s = set() e = E(1, 1) + E(1, 1) cnt = 1 while e.P != (1, 1): e = e + E(1, 1) cnt = cnt + 1 return cnt == target
def test(a, p): E.params(a, -a, p) s = set() e = E(1, 1) + E(1, 1) cnt = 1 while e.P != (1, 1): e = e + E(1, 1) cnt = cnt + 1 print(cnt)
def order(a): s = set((1, 1)) count = 0 Q = E(1, 1) while (Q + E(1, 1)).P not in s: Q = Q + E(1, 1) s.add(Q.P) count += 1 print(count) return count
def doubleAndAdd(P, n): R = E(0) Q = P while n > 0: if (n % 2) == 1: R = R + Q n = n // 2 Q = Q + Q return R
def fastMult(e, poww): res = E(0) z = e while (poww > 0): res = res + (poww % 2) * z poww = poww // 2 z = z + z return res
def check(p): a = 1 E.params(a, -a, p) while True: a += 1 E.params(a, -a, p) if doubleAndAdd(E(1, 1), 1000000) == E(0): print(a) if order(a) == 1000000: return a
def fastMult(e, poww): res = E(0) z = e while (poww > 0): res = res + (poww % 2) * z poww = poww // 2 z = z + z return res if __name__ == '__main__': p = 36028797018964019 q = 36028796930959053 a = 12730951283832694 E.params(a, -a, p) s = 788139760620004 e = 57233552642126 s1 = fastMult(E(1, 1), e).P[0] d = 8675309 s2 = ((d + s * s1) * inv(e, q)) % q print fastMult(E(1, 1), q) print fastMult(E(1, 1), s) print s1 print s2
res = res + (poww % 2) * z poww = poww // 2 z = z + z return res def test(a, p, target): E.params(a, -a, p) s = set() e = E(1, 1) + E(1, 1) cnt = 1 while e.P != (1, 1): e = e + E(1, 1) cnt = cnt + 1 return cnt == target if __name__ == '__main__': p = 1000003 trials = 100000 target = 1000000 for i in range(trials): a = random.randrange(1, p) E.params(a, -a, p) if E(0) == fastMult(E(1, 1), target): # see if order(E(1, 1)) | target if test(a, p, target): # see if order(E(1, 1)) == target print(str(a) + " " + str(p))
a = 12730951283832694 p = 36028797018964019 ph = 36028796930959053 def f(ee, pp, qq, P, Q): if 0 <= ee.P[0] < p / 3: return (ee + P, (pp + 1) % ph, qq) elif p / 3 <= ee.P[0] < 2 * p / 3: return (ee + ee, (pp * 2) % ph, (qq * 2) % ph) else: return (ee + Q, pp, (qq + 1) % ph) if __name__ == '__main__': E.params(a, -a, p) P = E(1, 1) Q = E(32676541629070164, 35161284104701659) a = f(P, 1, 0, P, Q) b = f(a[0], a[1], a[2], P, Q) cnt = 0 while a[0].P != b[0].P: a = f(a[0], a[1], a[2], P, Q) b = f(b[0], b[1], b[2], P, Q) b = f(b[0], b[1], b[2], P, Q) cnt = cnt + 1 if cnt % 100000 == 0: print(cnt)
from ec import E p = 977245356317 ph = 977244806323 def fastMult(e, poww): res = E(0) z = e while(poww > 0): res = res + (poww%2)*z poww = poww//2 z = z + z return res if __name__ == '__main__': E.params(454619944748, 67189121909, p) P = E(474177197796,218937542115) Q = E(287274742986,103070012816) print(fastMult(P, 777244806324)) E.params(508139, -508139, 900001) print(fastMult(E(1, 1), 10000))
def fastMult(e, poww): res = E(0) z = e while (poww > 0): res = res + (poww % 2) * z poww = poww // 2 z = z + z return res if __name__ == '__main__': p = nextprime((1 << 55) + random.randrange(0, 1 << 8)) a = random.randrange(p / 4, 3 * p / 4) E.params(a, -a, p) lb = long(p - 2 * sqrt(p)) ub = long(p + 2 * sqrt(p)) # tries 4*sqrt(p), but rho algorithm takes sqrt(p)... just BRUTE # let's assume professor's checking code timeouts in a minute. RUN THIS FOR FOUR MINUTES THEN z = fastMult(E(1, 1), lb) for q in range(0, long(4 * sqrt(p))): if q % long(4 * sqrt(p) / 100) == 0: perc = long(q / (4 * sqrt(p)) * 100 + 0.5) print(perc) if z == E(0): print(a, p, lb + q)