2017-05-06 19:32:27 +02:00
|
|
|
# PrimeModule-ext
|
|
|
|
|
2021-10-24 18:22:14 +02:00
|
|
|
C++ header-only library, binary and FFI library for factorizing huge (up to 2^63-1) numbers (optimized for huge semiprimes).
|
2017-05-06 19:32:27 +02:00
|
|
|
|
2021-10-24 18:22:14 +02:00
|
|
|
## Install
|
2017-05-06 20:42:08 +02:00
|
|
|
|
2021-10-24 18:22:14 +02:00
|
|
|
Arch Linux (AUR):
|
|
|
|
```bash
|
|
|
|
paru -S primemodule
|
2017-08-16 15:59:29 +02:00
|
|
|
```
|
2017-05-06 19:40:06 +02:00
|
|
|
|
2021-10-24 18:22:14 +02:00
|
|
|
Debian/Ubuntu:
|
2017-05-06 19:40:06 +02:00
|
|
|
```
|
2021-10-24 18:22:14 +02:00
|
|
|
sudo apt-get install build-essential && git clone https://github.com/danog/PrimeModule-ext && cd PrimeModule-ext && make -j$(nproc) && sudo make install
|
2017-05-06 19:40:06 +02:00
|
|
|
```
|
|
|
|
|
2021-10-24 18:22:14 +02:00
|
|
|
## API
|
2017-05-06 20:28:08 +02:00
|
|
|
|
2021-10-24 18:22:14 +02:00
|
|
|
### Binary
|
2017-05-06 20:28:08 +02:00
|
|
|
|
2021-10-24 18:22:14 +02:00
|
|
|
```bash
|
|
|
|
primemodule number
|
|
|
|
```
|
2017-05-06 20:28:08 +02:00
|
|
|
|
2021-10-24 18:22:14 +02:00
|
|
|
On success (return code 0), prints to stdout one of the prime factors of `number`.
|
2017-05-06 20:28:08 +02:00
|
|
|
|
2021-10-24 18:22:14 +02:00
|
|
|
### C++
|
2017-05-06 20:28:08 +02:00
|
|
|
|
2021-10-24 18:22:14 +02:00
|
|
|
```c++
|
|
|
|
uint32_t PrimeModule::factorize(uint64_t number);
|
2017-05-06 19:40:06 +02:00
|
|
|
```
|
|
|
|
|
2021-10-24 18:22:14 +02:00
|
|
|
Returns one of the prime factors of `number`, throws an std::runtime_error on failure.
|
2017-05-06 19:40:06 +02:00
|
|
|
|
2021-10-24 18:22:14 +02:00
|
|
|
### C
|
|
|
|
|
|
|
|
```c
|
|
|
|
int64_t factorize(uint64_t number);
|
2017-05-06 19:40:06 +02:00
|
|
|
```
|
|
|
|
|
2021-10-24 18:22:14 +02:00
|
|
|
Returns one of the prime factors of `number`, returns -1 on failure.
|
|
|
|
|
|
|
|
|
|
|
|
### PHP
|
|
|
|
|
|
|
|
```php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
$f = FFI::load("/usr/include/primemodule-ffi.h");
|
|
|
|
|
|
|
|
// Always pass strings to allow 64-bit factorization with no loss of precision on 32-bit PHP.
|
|
|
|
var_dump($f->factorizeFFI("2189285106422392999"));
|
|
|
|
```
|
2017-05-06 19:32:27 +02:00
|
|
|
|
2021-10-24 18:22:14 +02:00
|
|
|
Returns one of the prime factors of `2189285106422392999`, returns -1 on failure.
|