Path: blob/master/shared/small_roots/nitaj_fouotsa.py
2589 views
import logging12from sage.all import ZZ34from shared import small_roots567def modular_trivariate(f, e, m, t, X, Y, Z, roots_method="groebner"):8"""9Computes small modular roots of a trivariate polynomial.10More information: Nitaj A., Fouotsa E., "A New Attack on RSA and Demytko's Elliptic Curve Cryptosystem" (Section 3)11:param f: the polynomial12:param e: the modulus13:param m: the parameter m14:param t: the parameter t15:param X: an approximate bound on the x roots16:param Y: an approximate bound on the y roots17:param Z: an approximate bound on the z roots18:param roots_method: the method to use to find roots (default: "groebner")19:return: a generator generating small roots (tuples of x, y, and z roots) of the polynomial20"""21f = f.change_ring(ZZ)22pr = f.parent()23x, y, z = pr.gens()2425logging.debug("Generating shifts...")2627shifts = []28for k in range(m + 1):29for i1 in range(k, m + 1):30i2 = k31i3 = m - i132g = x ** (i1 - k) * z ** i3 * f ** k * e ** (m - k)33shifts.append(g)3435i1 = k36for i2 in range(k + 1, i1 + t + 1):37i3 = m - i138h = y ** (i2 - k) * z ** i3 * f ** k * e ** (m - k)39shifts.append(h)4041L, monomials = small_roots.create_lattice(pr, shifts, [X, Y, Z])42L = small_roots.reduce_lattice(L)43polynomials = small_roots.reconstruct_polynomials(L, f, e ** m, monomials, [X, Y, Z])44for roots in small_roots.find_roots(pr, polynomials, method=roots_method):45yield roots[x], roots[y], roots[z]464748