PHPackages                             danog/primemodule - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. danog/primemodule

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

danog/primemodule
=================

Prime module capable of doing prime factorization of huge numbers very quickly."

1.0.13(2y ago)18758.9k—0.5%36AGPL-3.0-onlyPHPPHP ^8.0

Since Mar 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/danog/PrimeModule)[ Packagist](https://packagist.org/packages/danog/primemodule)[ RSS](/packages/danog-primemodule/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (21)Used By (6)

PrimeModule
===========

[](#primemodule)

[![Build Status](https://camo.githubusercontent.com/6be15b3b2a9650ee816bccf6e2c5cd834b456a7ce9a597391feb5fe6edb8aa12/68747470733a2f2f7472617669732d63692e6f72672f64616e6f672f5072696d654d6f64756c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/danog/PrimeModule)

Prime module capable of doing prime factorization of huge numbers very quickly.

It can factorize huge numbers (even bigger than `PHP_INT_MAX` thanks to the wolfram alpha/python modules) very quickly.

Installation:
-------------

[](#installation)

Install with composer.

```
composer require danog/primemodule

```

Install python to enable the python module and the PHP curl extension to enable the wolfram alpha module.

Usage:
------

[](#usage)

This library has 4 prime factorization modules (ordered by speed, huge semiprime is usually a 20 digit semiprime generated by [telegram](https://core.telegram.org), see the travis ci tests for more stats):

- native\_cpp - A [native c++](https://github.com/danog/PrimeModule-ext) factorization module (it's the fastest), medium time 0.03943687915802 tested with 100 huge semiprime
- python - A [quadratic sieve](http://codegolf.stackexchange.com/questions/8629/fastest-semiprime-factorization) python module (usually it's faster than the pollard brent module, other times it just gets stuck (and then killed after 10 seconds by the lib), medium time 0.35134809732437 seconds calculated using 100 huge semiprimes, some of which caused the module to freeze and be killed. Usually it's 10 times faster than the pollard brent module)
- python\_alt - A [pollard brent](https://stackoverflow.com/questions/4643647/fast-prime-factorization-module) module also written in python (medium time 0.1801231908798 seconds calculated using 100 huge semiprimes)
- wolfram - A [wolfram alpha](https://wolframalpha.com) module (usually takes around 2.1294961380959 seconds calculated using 100 huge semiprimes)
- native - A [native PHP lopatin](https://github.com/LonamiWebs/Telethon/blob/master/telethon/crypto/factorizator.py) module (usually takes around 2.5698633241653 seconds calculated using 100 huge semiprimes, may sometimes be faster than the wolfram module: for example on HHVM native factorization usually takes 0.1 seconds)

These modules can be used either in the single variant, which returns only one factor (useful for semiprime factorization), or the full methods, that return an array with all of the factors.

This module was created to do semiprime factorization, so it might not perform very well with composite numbers.

The python/wolframalpha modules accept numeric strings bigger than `PHP_INT_MAX`, and if the factors are bigger than `PHP_INT_MAX` they will also returned as a string.

An automatic function can also be used, which chooses automatically the module in the following order: python\_alt, python, native, wolfram.

```
require 'vendor/autoload.php';

// quadratic sieve factorization
$factor = \danog\PrimeModule::python_single(2768594593405030913); // returns 1455582581 or 1902052573
// pollard brent sieve factorization
$factor = \danog\PrimeModule::python_single_alt(2768594593405030913); // returns 1455582581 or 1902052573
// native PHP single factorization
$factor = \danog\PrimeModule::native_single(2768594593405030913); // returns 1455582581 or 1902052573
// wolfram factorization
$factor = \danog\PrimeModule::wolfram_single(2768594593405030913); // returns 1455582581 or 1902052573
// automatic factorization
$factor = \danog\PrimeModule::auto_single(2768594593405030913); // returns 1455582581 or 1902052573

// quadratic sieve factorization
$factor = \danog\PrimeModule::python(15); // returns an array with 3 and 5
// pollard brent sieve factorization
$factor = \danog\PrimeModule::python_alt(15); // returns an array with 3 and 5
// native PHP factorization
$factor = \danog\PrimeModule::native(15); // returns an array with 3 and 5
// wolfram factorization
$factor = \danog\PrimeModule::wolfram(15); // returns an array with 3 and 5
// automatic factorization
$factor = \danog\PrimeModule::auto(15); // returns an array with 3 and 5

```

See `tests/testing.php` for more detailed examples.

Library created by Daniil Gentili ()

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity46

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 91.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~100 days

Recently: every ~44 days

Total

20

Last Release

1087d ago

PHP version history (3 changes)1.0.7PHP &gt;=7.0

1.0.8PHP ^8.0

1.0.9.9998PHP \*

### Community

Maintainers

![](https://www.gravatar.com/avatar/e1586cd637028e4f8da85f2252b8f4b81e05f6b17a93f92c34ff064dd838e6bb?d=identicon)[danog](/maintainers/danog)

---

Top Contributors

[![danog](https://avatars.githubusercontent.com/u/7339644?v=4)](https://github.com/danog "danog (54 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (3 commits)")[![LeTraceurSnork](https://avatars.githubusercontent.com/u/11344267?v=4)](https://github.com/LeTraceurSnork "LeTraceurSnork (1 commits)")[![vahidvdn](https://avatars.githubusercontent.com/u/11078601?v=4)](https://github.com/vahidvdn "vahidvdn (1 commits)")

---

Tags

factorizationhugephpprimepythonsemiprime

### Embed Badge

![Health badge](/badges/danog-primemodule/health.svg)

```
[![Health](https://phpackages.com/badges/danog-primemodule/health.svg)](https://phpackages.com/packages/danog-primemodule)
```

###  Alternatives

[marcj/topsort

High-Performance TopSort/Dependency resolving algorithm

24815.6M50](/packages/marcj-topsort)[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4205.3M84](/packages/livewire-volt)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
