defCJLOSS(A, s): n = len(A) N = ceil(sqrt(n)) L = matrix(QQ, n + 1) for i inrange(n): L[i, i] = 1 L[n, i] = 1/2 L[i, n] = N * A[i] L[n, n] = N * s res = L.LLL() for v in res: ifall(x in [-1/2, 1/2] for x in v[:-1]): out = [1/2 - a for a in v[:-1]] return out
通过对一般的隐藏数问题的扩展我们可以得到扩展隐藏数问题:给定素数,对整数,有: 其中以及均已知,而未知整数对于一个已知的整数满足,给出条方程: 其中对于,,以及均为已知的整数,未知正整数的上界为且已知,则扩展隐藏数问题(EHNP)则是通过上述条件恢复. 为解决EHNP,我们可以构造格: 其中: 设,,计算: 通过,我们可以得到满足。令 我们需要根据上述的构造格,在格中找到向量使得: 通过LLL算法对我们构造的格进行规约可以得到: 然后令(),最后计算: 这样得到的就是我们需要的. 在论文Extended Hidden Number Problem and Its Cryptanalytic Applications中还提及了一种通过狄利克雷近似计算双洞隐藏数问题(Hidden Number Problem with Two Holes, HNP-2H),具体方法与步骤在通过狄利克雷近似解决HNP-2H | Triode Field有写.
defsmall_roots(f, bounds, m=1, d=None): import itertools ifnot d: d = f.degree() R = f.base_ring() N = R.cardinality() f /= f.coefficients().pop(0) f = f.change_ring(ZZ) G = Sequence([], f.parent()) for i inrange(m + 1): base = N ^ (m - i) * f ^ i for shifts in itertools.product(range(d), repeat=f.nvariables()): g = base * prod(map(power, f.variables(), shifts)) G.append(g) B, monomials = G.coefficients_monomials() monomials = vector(monomials) factors = [monomial(*bounds) for monomial in monomials] for i, factor inenumerate(factors): B.rescale_col(i, factor) B = B.dense_matrix().LLL() B = B.change_ring(QQ) for i, factor inenumerate(factors): B.rescale_col(i, 1 / factor) H = Sequence([], f.parent().change_ring(QQ)) for h infilter(None, B * monomials): H.append(h) I = H.ideal() if I.dimension() == -1: H.pop() elif I.dimension() == 0: roots = [] for root in I.variety(ring=ZZ): root = tuple(R(root[var]) for var in f.variables()) roots.append(root) return roots return []