Path: blob/master/shared/small_roots/boneh_durfee.py
2589 views
import logging12from sage.all import ZZ34from shared import small_roots567def modular_bivariate(f, e, m, t, X, Y, roots_method="groebner"):8"""9Computes small modular roots of a bivariate polynomial.10More information: Boneh D., Durfee G., "Cryptanalysis of RSA with Private Key d Less than N^0.292"11:param f: the polynomial12:param e: the modulus13:param m: the amount of normal shifts to use14:param t: the amount of additional shifts to use15:param X: an approximate bound on the x roots16:param Y: an approximate bound on the y roots17:param roots_method: the method to use to find roots (default: "groebner")18:return: a generator generating small roots (tuples of x and y roots) of the polynomial19"""20f = f.change_ring(ZZ)21pr = f.parent()22x, y = pr.gens()2324logging.debug("Generating shifts...")2526shifts = []27for k in range(m + 1):28for i in range(m - k + 1):29g = x ** i * f ** k * e ** (m - k)30shifts.append(g)3132for j in range(t + 1):33h = y ** j * f ** k * e ** (m - k)34shifts.append(h)3536L, monomials = small_roots.create_lattice(pr, shifts, [X, Y])37L = small_roots.reduce_lattice(L)38polynomials = small_roots.reconstruct_polynomials(L, f, e ** m, monomials, [X, Y])39for roots in small_roots.find_roots(pr, polynomials, method=roots_method):40yield roots[x], roots[y]414243