I wonder if anyone can help me. below is code from my pollards rho attempt (for the integer factoring fans out there). However, im not getting the desired result. I believe its my implementation of the Euclidean algorithm as a method for gcd but im not sure.
I get an answer of -1 when n is 319 and -31 when n is 2759.
If anyone can help itd be greatly appreciated. Cheers
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
int gcd(int a, int b){
if (b == 0){
return a;
}
else{
gcd(b, a % b);
}
}
int pollardsrho(int n){
int d, x, y, c, p, q, fy;
d = 1;
x = 2;
y = 2;
c = 1;
while (d == 1){
x = (((x*x)+c) % n); //f(x) = x^2 + c mod n
fy = (((y*y)+c) % n);
y = (((fy*fy)+c) % n);
d = gcd((x-y), n);
if (d<n)
p = d;
}
printf("p = %d\n", p);
}
int main(void){
int n = 319;
pollardsrho;
}
I get an answer of -1 when n is 319 and -31 when n is 2759.
If anyone can help itd be greatly appreciated. Cheers
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
int gcd(int a, int b){
if (b == 0){
return a;
}
else{
gcd(b, a % b);
}
}
int pollardsrho(int n){
int d, x, y, c, p, q, fy;
d = 1;
x = 2;
y = 2;
c = 1;
while (d == 1){
x = (((x*x)+c) % n); //f(x) = x^2 + c mod n
fy = (((y*y)+c) % n);
y = (((fy*fy)+c) % n);
d = gcd((x-y), n);
if (d<n)
p = d;
}
printf("p = %d\n", p);
}
int main(void){
int n = 319;
pollardsrho;
}