Coder Social home page Coder Social logo

factor's Introduction

factor

Fast prime factorization in Python. Factors most 50-60 digit numbers within a minute or so (with PyPy).
The algorithm used depends on the size of the input

  • pollardPm1.py contains an implementation of the large prime (two stage) variant of Pollard's p-1 algorithm.
  • pollardRho.py contains an implementation of Pollard's Rho algorithm with Brent's improvements.
  • ecm.py contains an implementation of Lenstra's elliptic curve factorization algorithm. It is inversionless (since it uses Montgomery coordinates), uses two stages, and uses Suyama's parametrization to generate random elliptic curves. It also contains an implementation of Montgomery's PRAC algorithm for scalar multiplication (thanks Paul Zimmerman!) but this turned out to be slower than the usual double-and-add algorithm weirdly.
  • primeSieve.py contains a bunch of prime sieves (Atkin, Eratosthenes, segmented Eratosthenes). Look at the file for specific benchmarks.

Usage

All you have to do is run the file factor.py, enter a number, and hit Enter. Here's an example in terminal:

python factor.py
Enter a number: 15

Factoring 15...
Number of digits: 2
Finding small prime factors...
Prime factors found: 3, 5

15 = 3^1 * 5^1

Time: 5.00679016113e-05 s

and another...

Enter number: 37897387397398739739826929827929827927927762729872987928

Factoring 37897387397398739739826929827929827927927762729872987928...
Number of digits: 56
Finding small prime factors...
Prime factors found: 2, 3
Factoring 1579057808224947489159455409497076163663656780411374497 with ECM...
Number of digits: 55
Bounds: 250000 128992510
Sieving primes...
Stage 2 found factor!
Found factor 67246307
Factoring 67246307...
Number of digits: 8
67246307 is prime!
Factoring 23481702991138940747474138758238071923617408171...
Number of digits: 47
Factoring 23481702991138940747474138758238071923617408171 with ECM...
Number of digits: 47
Bounds: 50000 12746592
Sieving primes...
Tried 40 random curves...
Tried 80 random curves...
Tried 120 random curves...
Tried 160 random curves...
Stage 2 found factor!
Found factor 4788272261623351
Factoring 4788272261623351...
Number of digits: 16
4788272261623351 is prime!
Factoring 4904003303934522319753958187821...
Number of digits: 31
4904003303934522319753958187821 is prime!

37897387397398739739826929827929827927927762729872987928 = 2^3 * 3^1 * 67246307^1 * 4788272261623351^1 * 4904003303934522319753958187821^1

Time: 24.7774269581 s

References

factor's People

Contributors

nishanth17 avatar

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.