コード例 #1
0
ファイル: sieve-lat.py プロジェクト: JoeyL12138/nfs
def main():
    (n, nfsPoly, m, B, M, K) = files.loadParamsFile()

    afBase = files.loadFileArray("afbase.txt")
    rfBase = files.loadFileArray("rfbase.txt")
    smoothsFile = open("smooths.txt", "w")
    smoothsCount = 0
    q = B
    K += K / 10

    specialqFile = open("specialq.txt", "w")
    while (smoothsCount < K):
        while (True):
            q = primemath.nextPrime(q)
            roots = poly.getRootsModPFast(poly.Poly(nfsPoly), q)
            if (len(roots) > 0):
                break

        roots.sort()
        for s in roots:
            specialqFile.write(str([s, q]) + "\n")
            print "special_q: %s" % [q, s]

            I = 1024
            J = 512
            smooths = sieve_special_q(q, s, I, J, rfBase, afBase,
                                      (n, nfsPoly, m, B, M, K))
            smoothsCount += len(smooths)
            print "total smooths: %s/%s" % (smoothsCount, K)
            smoothsFile = open("smooths.txt", "a")
            for smooth in smooths:
                smoothsFile.write(str(smooth) + "\n")

            smoothsFile.close()
コード例 #2
0
ファイル: sieve-lat.py プロジェクト: paulocode/ppyNFS
def main():
	(n,nfsPoly,m,B,M,K) = files.loadParamsFile()
	
	afBase = files.loadFileArray("afbase.txt")
	rfBase = files.loadFileArray("rfbase.txt")
	smoothsFile = open("smooths.txt", "w")
	smoothsCount = 0
	q = B
	K+=K/10
	
	specialqFile = open("specialq.txt", "w")
	while(smoothsCount < K):
		while(True):
			q = primemath.nextPrime(q)
			roots = poly.getRootsModPFast(poly.Poly(nfsPoly),q)
			if(len(roots) > 0):
				break
			
		roots.sort()
		for s in roots:
			specialqFile.write(str([s,q])+"\n")
			print "special_q: %s" % [q,s]
			
			I = 1024
			J = 512
			smooths = sieve_special_q(q,s,I,J,rfBase,afBase,(n,nfsPoly,m,B,M,K))	
			smoothsCount += len(smooths)
			print "total smooths: %s/%s" % (smoothsCount,K)
			smoothsFile = open("smooths.txt", "a")
			for smooth in smooths:
				smoothsFile.write(str(smooth)+"\n")
					
			smoothsFile.close()	
コード例 #3
0
ファイル: matrixmath.py プロジェクト: JoeyL12138/nfs
def generateQCBase(n, p, nfsPoly):
    qcbase = []
    while (len(qcbase) < 3 * math.log(n, 10)):
        p = primemath.nextPrime(p)
        roots = poly.getRootsModPFast(nfsPoly, p)
        for root in roots:
            if (nfsPoly.derivative().evaluate(root) % p != 0):
                qcbase.append([root, p])
    return qcbase
コード例 #4
0
ファイル: matrixmath.py プロジェクト: paulocode/ppyNFS
def generateQCBase(n,p,nfsPoly):
	qcbase = []
	while(len(qcbase) < 3*math.log(n,10)):
		p = primemath.nextPrime(p)
		roots = poly.getRootsModPFast(nfsPoly,p)
		for root in roots:
			if(nfsPoly.derivative().evaluate(root) % p != 0):
				qcbase.append([root,p])
	return qcbase	
		
コード例 #5
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])
コード例 #6
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])
コード例 #7
0
ファイル: tests.py プロジェクト: JoeyL12138/nfs
	def test_polyRootModPFast(self):
		# Briggs
		polynomial = poly.Poly([8,29,15,1])
		testRoots = poly.getRootsModPFast(polynomial,67)
		correctRoots = [2,44,6]
		correctRoots.sort()
		testRoots.sort()
		
		self.assertEqual(len(correctRoots),len(testRoots))
		
		for i in range(len(correctRoots)):
			self.assertEqual(correctRoots[i], testRoots[i])
コード例 #8
0
ファイル: tests.py プロジェクト: JoeyL12138/nfs
	def test_polyRootModPFastDeg5_2(self):
		p = 157
		polynomial = poly.Poly([11,1])*poly.Poly([-23,1])*poly.Poly([-1,1])*poly.Poly([-1,1])*poly.Poly([-1,1])
		correctRoots = poly.getRootsModPSlow(polynomial,p)
		testRoots = poly.getRootsModPFast(polynomial,p)

		correctRoots.sort()
		testRoots.sort()
		
		self.assertEqual(len(correctRoots),len(testRoots))
		
		for i in range(len(correctRoots)):
			self.assertEqual(correctRoots[i], testRoots[i])
コード例 #9
0
ファイル: tests.py プロジェクト: JoeyL12138/nfs
	def test_polyRootModPFastRandomDeg5(self):
		# no roots
		p = 503
		polynomial = poly.Poly([2034,234,24,123,101,1])
		correctRoots = poly.getRootsModPSlow(polynomial,p)
		testRoots = poly.getRootsModPFast(polynomial,p)
		
		correctRoots.sort()
		testRoots.sort()
		
		self.assertEqual(len(correctRoots),len(testRoots))
		
		for i in range(len(correctRoots)):
			self.assertEqual(correctRoots[i], testRoots[i])
コード例 #10
0
ファイル: tests.py プロジェクト: JoeyL12138/nfs
	def test_polyRootModPFastRandomZeroRoot(self):
		
		p = 503
		polynomial = poly.Poly([0,1])*poly.Poly([-11,1])*poly.Poly([-51,1])*poly.Poly([-231,1])
		correctRoots = poly.getRootsModPSlow(polynomial,p)
		testRoots = poly.getRootsModPFast(polynomial,p)

		correctRoots.sort()
		testRoots.sort()
		
		self.assertEqual(len(correctRoots),len(testRoots))
		
		for i in range(len(correctRoots)):
			self.assertEqual(correctRoots[i], testRoots[i])
コード例 #11
0
ファイル: test-specialq.py プロジェクト: paulocode/ppyNFS
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])
コード例 #12
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])
コード例 #13
0
ファイル: init.py プロジェクト: JoeyL12138/nfs
	(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
			
	afBaseFile.close()
	rfBaseFile.close()
	
	K += 10

	paramsFile = open("params.txt", "w")
	paramsFile.write("n = " +str(n)+"\n")
	paramsFile.write("B = " +str(B)+"\n")
	paramsFile.write("M = " +str(M)+"\n")
	paramsFile.write("nfsPoly = " +str(nfsPoly)+"\n")
	paramsFile.write("m = " +str(m)+"\n")
コード例 #14
0
ファイル: init.py プロジェクト: paulocode/ppyNFS
	(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
			
	afBaseFile.close()
	rfBaseFile.close()
	
	K += 10

	paramsFile = open("params.txt", "w")
	paramsFile.write("n = " +str(n)+"\n")
	paramsFile.write("B = " +str(B)+"\n")
	paramsFile.write("M = " +str(M)+"\n")
	paramsFile.write("nfsPoly = " +str(nfsPoly)+"\n")
	paramsFile.write("m = " +str(m)+"\n")