tifa
Fast factorization of integers of up to about 280 bits (84 digits), with the TIFA C library: its quadratic sieve, elliptic curves and smaller methods, chosen by the size of the number.
>>> import tifa
>>> tifa.factor(360)
{2: 3, 3: 2, 5: 1}
>>> tifa.factor(2**64 + 1)
{274177: 1, 67280421310721: 1}
>>> tifa.factor(1)
{}
factor(n) returns the prime factorization of a positive integer as
{prime: exponent}, primes in increasing order, like SymPy's factorint.
n can be an int or any integer type with __index__ (NumPy's, gmpy2's).
Speed
One thread, balanced semiprimes (the hardest numbers of a size), on an AMD EPYC 9V45:
| bits | 100 | 140 | 180 | 220 |
|---|---|---|---|---|
tifa.factor |
0.7 ms | 9.6 ms | 0.18 s | 3.0 s |
PARI/GP 2.15 factorint |
1.9 ms | 39 ms | 0.55 s | 9.0 s |
Numbers with small factors take much less. From 180 bits the time doubles about every 10 to 12 bits: on an Apple M5 Pro, about 9 s at 240 bits, 24 s at 256 and 2 minutes at 280.
Hints
When something is known of n, a hint saves time:
tifa.factor(n, hint="balanced") # two primes of about the same size
tifa.factor(n, hint="unbalanced") # a prime factor under a third of its size
A hint never changes the result, but a wrong one can cost much more time than none.
Threads
factor releases the GIL, so that threads factor in parallel:
from concurrent.futures import ThreadPoolExecutor
with ThreadPoolExecutor() as pool:
results = list(pool.map(tifa.factor, numbers))
Time limits
try:
factors = tifa.factor(n, timeout=60)
except tifa.FactorizationTimeout as e:
print("not done in a minute:", e.factors)
FactorizationTimeout is a TimeoutError, and a FactorizationError:
its factors hold what was found, which multiply to n.
prime_certificate(p, timeout=60) raises TimeoutError. The limit is
approximate: the algorithms check the time now and then (SIQS every 16
chunks of its sieve, ECM after each curve), so that a call can end a little
after it, by a millisecond from 240 to 280 bits on an Apple M5 Pro, a few
tens at most. Ctrl-C does not interrupt factor: a time limit is the way to
bound it.
Tuning
The parameters of the algorithms were tuned on an Apple M5 Pro and recent
x86-64 processors; others may want their own, above 240 bits most. The
package installs tifa-tune, which measures them on the machine and writes
them to files that set_tuning_dir points the package at:
tifa-tune --algo siqs --sizes 232,248,264,280 --search descent --trials 2 \
--fit 8 --out /path/to/tuning
tifa.set_tuning_dir("/path/to/tuning")
Each file applies to the sizes it was tuned for, give or take 8 bits.
set_tuning_dir holds for the whole process; until it is called, the
directory is that of the TIFA_TUNING_DIR environment variable, if set.
set_tuning_dir("") keeps the built-in parameters alone. tifa-tune --help
lists its options, which
TIFA's README explains;
the example above takes a few hours.
Errors
TypeError if n is not an integer, ValueError if it is not positive
or the hint is unknown. In the rare event that n can not be factored
completely (or, with proof=True, a factor not proven prime),
tifa.FactorizationError is raised, its factors attribute holding what
was found (factors that multiply to n, some of them not prime).
Proofs
The primes are told from composites by a Baillie-PSW test, which no
composite is known to pass, but which proves nothing above 2^64.
proof=True also proves them prime:
tifa.factor(n, proof=True)
prime_certificate(p) returns the proof, which anyone can check:
check_certificate does, in plain Python.
>>> cert = tifa.prime_certificate(2**89 - 1)
>>> cert
[(618970019642690137449562111, [(2, 3), (3, 3), (5, 3), (17, 3), (23, 3), (89, 2), (353, 3), (397, 3)])]
>>> tifa.check_certificate(2**89 - 1, cert)
True
Each step (p, [(q, a), ...]) proves p prime from primes q of p - 1
and integers a (Pocklington's theorem, and Brillhart, Lehmer and
Selfridge's); a step (p, [(q, a), ...], D, [(r, P), ...]) also uses
primes r of p + 1, with Lucas sequences of discriminant D and
parameters P (Morrison's theorem). Each q and r is below 2^64 or
proven by an earlier step; a prime below 2^64 needs no step. The
certificate is plain data: json.dumps saves it.
On an Apple M5 Pro, a proof takes 0.5 ms on average at 128 bits, 5.5 ms at
192 bits, 53 ms at 224 bits and 66 ms at 256 bits (up to about a second
when both p - 1 and p + 1 are hard to factor). On random numbers of 100
to 200 bits, factor(n, proof=True) takes 2% to 25% more time than
factor(n). Without proof=True, nothing changes.
Installing
From PyPI:
pip install tifa-factor
Wheels exist for Linux (x86-64 and arm64, glibc and musl) and macOS (arm64 and x86-64, 11.0 and later), for Python 3.10 and later; GMP comes in them. Elsewhere, pip builds the package from source.
From a checkout of TIFA, at the top of the tree:
pip install ".[test]" # or "pip install ." without pytest
python -m pytest # the tests
A build from source needs a C compiler, CMake 3.26 or later (pip fetches it
if the system's is older) and GMP with its headers (libgmp-dev on
Debian and Ubuntu, gmp-devel on Fedora, brew install gmp on macOS). A
GMP installed elsewhere than in the usual places is found through
GMP_ROOT, the directory holding its include and lib:
GMP_ROOT=/opt/gmp pip install .
Licence
LGPL 2.1 or later, as TIFA. The wheels contain GMP 6.3.0
(gmplib.org), under the LGPL 3 (readme/license_v3.txt),
linked statically: pip install --no-binary tifa-factor tifa-factor builds
the package against the GMP of the system instead.
Metadata
Release files for tifa-factor 0.4.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tifa_factor-0.4.7.tar.gz | 655.0 kB | With provenance | Details for tifa_factor-0.4.7.tar.gz |
Built distributions (wheels)
Total release size: 6.7 MB
Release files / tifa_factor-0.4.7.tar.gz
| Download URL | tifa_factor-0.4.7.tar.gz |
|---|---|
| Size | 655.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d0a4ed8fa58a52001e5c6bae3331656aa3983720800dc6f34b8203face67b122
|
|
BLAKE2b-256 checksum How to use checksums |
f1dc8c32e703717bb9f8270d956f1127b712ba506e4ec8a24ab63d525d4f9874
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / tifa_factor-0.4.7-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | tifa_factor-0.4.7-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
380026cc18e1eaa67dd7081bba5fed63b0314048fdb7572bea14f150f59631d4
|
|
BLAKE2b-256 checksum How to use checksums |
f02f94c6d5d23e36dab392a289b312b2d969e335e5ca62de9068e691737728f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / tifa_factor-0.4.7-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | tifa_factor-0.4.7-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 966.8 kB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
937b676185139200f88f5a63b6efb97574aa19c7a1b352f895fdabe55f4ee9d0
|
|
BLAKE2b-256 checksum How to use checksums |
ba444856b2f79abda113924e88d3efb58fb225c9e05d63eab062960135d92859
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / tifa_factor-0.4.7-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
| Download URL | tifa_factor-0.4.7-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
821e77d225641fe81ffee6653b381449890522932f885ea5aef5a8616a51d1c2
|
|
BLAKE2b-256 checksum How to use checksums |
a082c23620230953b84d3e546bd6d9f2482fdf3936862a9b452acdb4cbe16b29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / tifa_factor-0.4.7-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
| Download URL | tifa_factor-0.4.7-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 951.7 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
96f9ba564f14d80fc4b747f7dbc8bb6e248c64968c3fdd425bc304193292da44
|
|
BLAKE2b-256 checksum How to use checksums |
a4bd21a6fdab3e18053e2643f71aaa2d76558ab495b1a3d38c9c6931cb11a56b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / tifa_factor-0.4.7-cp310-abi3-macosx_11_0_x86_64.whl
| Download URL | tifa_factor-0.4.7-cp310-abi3-macosx_11_0_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
3e7f715ee61e36fc2e943cf5efab5cb4f2d4849dfb8dc52e5e839e77500c56c3
|
|
BLAKE2b-256 checksum How to use checksums |
b6144b70131c8ca31b67d734af93a2cae711a1c82bf10eae59e3fced975ee38b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / tifa_factor-0.4.7-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | tifa_factor-0.4.7-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 884.3 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
d4f34f17a0213240c17fd4d6d3104c468b6acafa5d44721c73c206f00dbf798d
|
|
BLAKE2b-256 checksum How to use checksums |
bfe8d2254d06a4d6359623400d9db153ec8b69f437485cc17fa847e124139632
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logSecurity for tifa-factor 0.4.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 7 files in this release have been uploaded with provenance metadata.
Attestation for tifa_factor-0.4.7.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.