PrimeModule-ext/README.md

40 lines
906 B
Markdown
Raw Normal View History

2017-05-06 19:32:27 +02:00
# PrimeModule-ext
2017-05-06 20:28:08 +02:00
PHP extension for factorizing huge (up to 2^63-1) numbers (optimized for huge semiprimes).
2017-05-06 19:32:27 +02:00
2017-05-06 20:42:08 +02:00
To compile it, simply install https://github.com/CopernicaMarketingSoftware/PHP-CPP and run `make && sudo make install` in this directory.
2017-05-06 19:40:06 +02:00
API:
```
2017-05-06 20:28:08 +02:00
integer factorize( mixed $pq )
2017-05-06 19:40:06 +02:00
```
2017-05-06 20:28:08 +02:00
Parameters:
pq - The number to factorize, a string or an integer.
Return value: an integer, containing one of the factors of the number.
Example:
2017-05-06 19:40:06 +02:00
```
<?php
2017-05-06 20:28:08 +02:00
var_dump(factorize(1724114033281923457));
2017-05-06 19:40:06 +02:00
var_dump(factorize("2189285106422392999"));
2017-05-06 20:28:08 +02:00
var_dump(factorize(15));
2017-05-06 19:40:06 +02:00
```
This will output:
```
2017-05-06 20:28:08 +02:00
int(1402015859)
int(1117663223)
int(5)
2017-05-06 19:40:06 +02:00
```
As you can see, the factorize function accepts integers and strings as parameter, so that if you're poor and you have only a 32 bit system, you will still be able to provide 64 bit integers as a string.
2017-05-06 19:32:27 +02:00
2017-05-06 20:10:39 +02:00
The function can throw an \Exception if factorization fails.