Created
June 29, 2018 15:47
-
-
Save devcarmelo/523fcf8b4088270398bdca8521a40744 to your computer and use it in GitHub Desktop.
Implementación del algoritmo de Pollard Rho en PHP usando la librería GMP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function gmp_pollard_rho($number) { | |
| $one = gmp_init(1); | |
| $two = gmp_init(2); | |
| $n = $number instanceof GMP ? $number : gmp_init($number); | |
| if(gmp_mod($n, $two) == 0) { | |
| return $two; | |
| } | |
| $x = gmp_random_range($one, gmp_sub($n, $one)); | |
| $c = gmp_random_range($one, gmp_sub($n, $one)); | |
| $y = $x; | |
| $g = $one; | |
| while($g == $one) { | |
| $x = gmp_mod(gmp_add(gmp_mod(gmp_mul($x, $x), $n), $c), $n); | |
| $y = gmp_mod(gmp_add(gmp_mod(gmp_mul($y, $y), $n), $c), $n); | |
| $y = gmp_mod(gmp_add(gmp_mod(gmp_mul($y, $y), $n), $c), $n); | |
| $g = gmp_gcd(gmp_abs(gmp_sub($x, $y)), $n); | |
| } | |
| return $g; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment