GithubHelp home page GithubHelp logo

ppynfs's Introduction

ppyNFS

Number Field Sieve on python

The Number Field Sieve (NFS) is the asymptotically fastest integer factorization algorithm known. It is magnitudes more complicated than its younger brother, the Quadratic Sieve. The fact that a very complicated algorithm solves a (conceptually) very simple problem is what give its appeal (similar to FLT). This algorithm requires LOTS of sub-algorithms, and some code is copied from the implementations scattered throughout the internet. These will eventually be rewritten.

The goal of this project is to write an easy-to-understand implementation to ease learning of NFS-related concepts. Python allows overriding of operators, supports bignums natively, and is moderately popular for beginners. Here is a snippet of code that shows readability (see tests.py):

	# Brigg's example
	nfspoly = Poly([8,29,15,1])
	NF = NumberField(nfspoly)
	
	tomult = [[-1,1],[3,1],[13,1],[104,1],[3,2],[25,2],[-8,3],[48,5],[54,5],[-43,6],[-8,7],[11,7],[856,11]]
	tomult = [NF(Poly(x)) for x in tomult] # Transform each (a,b) into an element in the number field.
	nfspolyd = NF(nfspoly.derivative())
	
	prod = NF(Poly([1]))
	for x in tomult: # Multiply each (a,b) element.
		prod = prod * x
		
	prod = prod * nfspolyd * nfspolyd
	
	correctProduct = NF(Poly([22939402657683071224L, 54100105785512562427L, 22455983949710645412L])) # correct product, as per Briggs'
	self.assertEqual(prod,correctProduct)

A complete (dirty) implementation of NFS in python is being rewritten to ppyNFS, with the aims of making the code cleaner. Though, I don't claim that this code is absolutely tidy (cleanup is still needed in lots of places). The polynomial and number field logic is mostly rewritten. The main NFS stages that has been rewritten are:

[X] init

[X] trialdivide

[ ] sieve-line

[ ] filter

[X] matrix-gauss

[X] sqrt-couv

Also, stages that were not in the old code but would be nice to have in ppyNFS are:

[ ] matrix-lanc

[X] sieve-lat

[ ] sqrt-nguy

The completed parts is enough to run a basic NFS factorization. To do this, run:

python2.7 init.py python2.7 sieve-lat.py python2.7 filter.py python2.7 matrix-gauss.py python2.7 sqrt-couv.py

can not run with python3 LLL code is from https://github.com/kutio/liblll. Unless otherwise stated, the code is in public domain.

ppynfs's People

Contributors

gongchunye avatar paulocode avatar

Forkers

phdtai

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.