for m inrange(1025): print(m, len(candidates)) candidates_ = set() mask = (2 << m) - 1 for x, y in candidates: if f1(x, y) == a and f2(x, y) == b: p, q = x, y d = gmpy2.invert(65537, (p - 1) * (q - 1)) m = pow(c, d, p * q) print(bytes.fromhex(hex(m)[2:])) exit() for bx inrange(2): for by inrange(2): xx = x + (bx << m) yy = y + (by << m) if f1(xx, yy) & mask != a & mask: continue if f2(xx, yy) & mask != b & mask: continue candidates_.add((xx, yy)) candidates = candidates_