
# This file was *autogenerated* from the file partial_key_exposure.sage
from sage.all_cmdline import *   # import sage library

_sage_const_2 = Integer(2); _sage_const_1 = Integer(1); _sage_const_0 = Integer(0); _sage_const_7 = Integer(7); _sage_const_4 = Integer(4); _sage_const_1024 = Integer(1024); _sage_const_200 = Integer(200); _sage_const_0p5 = RealNumber('0.5')
load("coppersmith_univariate.sage")
def partial_key_exposure(input):

	length_N = _sage_const_1024 
	p = next_prime(_sage_const_2 **int(round(length_N/_sage_const_2 )))
	q = next_prime(round(pi.n()*p))
	N = p*q
	print "N"
	print N

	hidden = _sage_const_200  
	diff = ZZ.random_element(_sage_const_0 ,_sage_const_2 **hidden - _sage_const_1 )
	qbar = q + diff
	print "qbar"
	print  qbar
	
	F = PolynomialRing(Zmod(N), implementation='NTL', names=('x',)); (x,) = F._first_ngens(1)
	pol = x - qbar
	dd = pol.degree()

	beta = _sage_const_0p5 
	epsilon = beta/_sage_const_7 
	mm = ceil(beta**_sage_const_2 /(dd*epsilon))
	tt = floor(dd*mm*((_sage_const_1 /beta)-_sage_const_1 ))
	XX = ceil(N**((beta**_sage_const_2 /dd)-epsilon))

	roots = coppersmith_howgrave_univariate(pol, N, beta, mm, tt, XX)
	for root in roots:
		if(root == qbar):
	
			roots.remove(root)
	result = {}
	result['results'] = roots
	result['errors']  = 'No error'
	if(len(roots) == _sage_const_0 ):
		result['errors'] = 'No solution found'
	return result
	
print partial_key_exposure(_sage_const_4 )

