Beispiel #1
0
def main():
    nfspoly = poly.Poly([8, 29, 15, 1])
    NF = poly.NumberField(nfspoly)
    while (True):
        q = primemath.generateLargePrime(10)
        s = poly.getRootsModPFast(nfspoly, q)
        if (len(s) > 0):
            break
    s = s[0]

    print "special_q: f(%s) = 0 mod %s" % (s, q)

    while (True):
        p = primemath.generateLargePrime(7)
        r = poly.getRootsModPFast(nfspoly, p)
        if (len(r) > 0):
            break
    r = r[0]

    print "p: f(%s) = 0 mod %s" % (r, p)

    basis = find_sublattice_basis(q, s, p, r)
    print "basis: %s" % basis
    basis_r = reduce_basis(basis[0], basis[1])
    a0 = basis_r[0][0]
    b0 = basis_r[0][1]
    a1 = basis_r[1][0]
    b1 = basis_r[1][1]
    print "reduced basis: %s" % [[a0, b0], [a1, b1]]

    print "generating lattice points..."
    for i in range(-20, 20):
        for j in range(-20, 20):
            a = a0 * i + a1 * j
            b = b0 * i + b1 * j
            if (a == 0 or b == 0):
                continue
            NFelement = NF(poly.Poly([a, b]))
            if (NFelement.norm() % q == 0 and NFelement.norm() % p == 0):
                print "%s is q-divisible and p-divisible" % [a, b]
            else:
                raise AssertionError("%s is not q-divisible or p-divisible" %
                                     [a, b])
def main():
	nfspoly = poly.Poly([8,29,15,1])
	NF = poly.NumberField(nfspoly)
	while(True):
		q = primemath.generateLargePrime(10)
		s = poly.getRootsModPFast(nfspoly,q)
		if(len(s) > 0):
			break
	s = s[0]

	print "special_q: f(%s) = 0 mod %s" %(s,q)
		
	while(True):
		p = primemath.generateLargePrime(7)
		r = poly.getRootsModPFast(nfspoly,p)
		if(len(r) > 0):
			break
	r = r[0]

	print "p: f(%s) = 0 mod %s" %(r,p)
		
	basis = find_sublattice_basis(q,s,p,r)
	print "basis: %s" % basis
	basis_r = reduce_basis(basis[0],basis[1])
	a0 = basis_r[0][0]
	b0 = basis_r[0][1]
	a1 = basis_r[1][0]
	b1 = basis_r[1][1]
	print "reduced basis: %s" % [[a0,b0],[a1,b1]]

	print "generating lattice points..."
	for i in range(-20,20):
		for j in range(-20,20):
			a = a0*i+a1*j
			b = b0*i+b1*j
			if(a == 0 or b == 0):
				continue
			NFelement = NF(poly.Poly([a,b]))
			if(NFelement.norm()%q == 0 and NFelement.norm()%p == 0):
				print "%s is q-divisible and p-divisible" % [a,b]
			else:
				raise AssertionError("%s is not q-divisible or p-divisible" % [a,b])
Beispiel #3
0
def generatePrimes(primes,nfsPoly,couvBound):		
	prodPrimes = 1
	sumBound = 0.0
	for prime in primes:
		sumBound += math.log(prime,2)
		prodPrimes *= prime
		
	while(sumBound <= couvBound):
		prime = primemath.generateLargePrime(64)
		if(not(poly.irreducibleModP(nfsPoly,prime))):
			continue
			
		sumBound += math.log(prime,2)
		primes.append(prime)
		prodPrimes *= prime
		print "%s/%s primes" % (int(sumBound/64)+1,int(couvBound/64)+1)
	return (primes,prodPrimes)
Beispiel #4
0
def generatePrimes(primes, nfsPoly, couvBound):
    prodPrimes = 1
    sumBound = 0.0
    for prime in primes:
        sumBound += math.log(prime, 2)
        prodPrimes *= prime

    while (sumBound <= couvBound):
        prime = primemath.generateLargePrime(64)
        if (not (poly.irreducibleModP(nfsPoly, prime))):
            continue

        sumBound += math.log(prime, 2)
        primes.append(prime)
        prodPrimes *= prime
        print "%s/%s primes" % (int(sumBound / 64) + 1,
                                int(couvBound / 64) + 1)
    return (primes, prodPrimes)
Beispiel #5
0
def main():
	nfspoly = poly.Poly([8,29,15,1])
	NF = poly.NumberField(nfspoly)
	while(True):
		q = primemath.generateLargePrime(20)
		r = poly.getRootsModPFast(nfspoly,q)
		if(len(r) > 0):
			break
	r = r[0]
	
	print "special_q: f(%s) = 0 mod %s" %(r,q)
	
	
	basis = []
	b = 1
	for i in range(2):
		a = -b*r + i*q
		basis.append([a,b])

	print "basis: %s" % basis
	basis_r = reduce_basis(basis[0],basis[1])
	a0 = basis_r[0][0]
	b0 = basis_r[0][1]
	a1 = basis_r[1][0]
	b1 = basis_r[1][1]
	print "reduced basis: %s" % [[a0,b0],[a1,b1]]
	
	print "generating lattice points..."
	for i in range(-2,2):
		for j in range(-2,2):
			a = a0*i+a1*j
			b = b0*i+b1*j
			if(a == 0 or b == 0):
				continue
			NFelement = NF(poly.Poly([a,b]))
			if(NFelement.norm()%q == 0):
				print "%s is q-divisible" % [a,b]
			else:
				raise AssertionError("%s is not q-divisible" % [a,b])
Beispiel #6
0
def main():
    nfspoly = poly.Poly([8, 29, 15, 1])
    NF = poly.NumberField(nfspoly)
    while (True):
        q = primemath.generateLargePrime(20)
        r = poly.getRootsModPFast(nfspoly, q)
        if (len(r) > 0):
            break
    r = r[0]

    print "special_q: f(%s) = 0 mod %s" % (r, q)

    basis = []
    b = 1
    for i in range(2):
        a = -b * r + i * q
        basis.append([a, b])

    print "basis: %s" % basis
    basis_r = reduce_basis(basis[0], basis[1])
    a0 = basis_r[0][0]
    b0 = basis_r[0][1]
    a1 = basis_r[1][0]
    b1 = basis_r[1][1]
    print "reduced basis: %s" % [[a0, b0], [a1, b1]]

    print "generating lattice points..."
    for i in range(-2, 2):
        for j in range(-2, 2):
            a = a0 * i + a1 * j
            b = b0 * i + b1 * j
            if (a == 0 or b == 0):
                continue
            NFelement = NF(poly.Poly([a, b]))
            if (NFelement.norm() % q == 0):
                print "%s is q-divisible" % [a, b]
            else:
                raise AssertionError("%s is not q-divisible" % [a, b])
Beispiel #7
0
import poly
import nfspolygen
import etcmath
import primemath
import math

if __name__ == '__main__':
	semiprimeSize = 100
	n = primemath.generateLargePrime(semiprimeSize/2)*primemath.generateLargePrime(semiprimeSize/2)	
	print "n = %s" % (n)
	
	d = 3
	(m,nfsPoly) = nfspolygen.generateNFSPoly(n,d)	
	print "Using poly %s, m = %s" % (nfsPoly,m)
	B = M = etcmath.calculateB(n)
	print "Using bound %s" % B
	prefactorBase = primemath.generatePrimes(B)
	
	K = (int)(3*math.log(n,10)) # for quadratic characters
	
	afBaseFile = open("afbase.txt", "w")
	rfBaseFile = open("rfbase.txt", "w")
	print "Generating af and rf bases..."	
	for p in prefactorBase:
		if(p > B): break
		rfBaseFile.write(str([m%p,p])+"\n")
		K += 1
		roots = poly.getRootsModPFast(nfsPoly,p)
		for root in roots:
			afBaseFile.write(str([root,p])+"\n")
			K += 1
Beispiel #8
0
import poly
import nfspolygen
import etcmath
import primemath
import math

if __name__ == '__main__':
	semiprimeSize = 64
	n = primemath.generateLargePrime(semiprimeSize/2)*primemath.generateLargePrime(semiprimeSize/2)	
	print "n = %s" % (n)
	
	d = 3
	(m,nfsPoly) = nfspolygen.generateNFSPoly(n,d)	
	print "Using poly %s, m = %s" % (nfsPoly,m)
	B = M = etcmath.calculateB(n)
	print "Using bound %s" % B
	prefactorBase = primemath.generatePrimes(B)
	
	K = (int)(3*math.log(n,10)) # for quadratic characters
	
	afBaseFile = open("afbase.txt", "w")
	rfBaseFile = open("rfbase.txt", "w")
	print "Generating af and rf bases..."	
	for p in prefactorBase:
		if(p > B): break
		rfBaseFile.write(str([m%p,p])+"\n")
		K += 1
		roots = poly.getRootsModPFast(nfsPoly,p)
		for root in roots:
			afBaseFile.write(str([root,p])+"\n")
			K += 1