def inverse(self): if self.degree() == 0: new_value = self.value[0].inverse() new = deepcopy(self) new.value = [new_value] return new a, b, c = extended_euclid(self, self.field.q) return c.inverse() * a
def pollard_rho(g, h, f): x, y = g.identity(), h.identity() a, b, c, d = 0, 0, 0, 0 for i in range(g.order()): x, a, b = f(x, a, b, g, h) y, c, d = f(y, c, d, g, h) y, c, d = f(y, c, d, g, h) if x == y: # found a collision u = (a-c) % g.order() v = (d-b) % g.order() # know that g^u=h^v inv, gcd = nt.extended_euclid(v, g.order())[::2] log_mod_gcd = ((u*inv) % g.order())//gcd reduced = g.p//gcd for j in range(gcd): if pow(g, log_mod_gcd+j*reduced) == h: return log_mod_gcd+j*reduced