Skip to content
Snippets Groups Projects
Commit f5b08711 authored by Gary Neveu's avatar Gary Neveu
Browse files

rho

parent 5d590025
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -14,12 +14,12 @@ struct hash_tbl {
typedef struct hash_tbl* hash_tbl;
hash_tbl htbl_empty(size_t (*h)(void*),
int (*eq)(void*, void*),
void (*free)(void*)){
hash_tbl htbl_empty(size_t (*h)(void*), int (*eq)(void*, void*), void (*free)(void*)){
}
int htbl_add(hash_tbl htbl, void* x){
}
int htbl_in(hash_tbl htbl, void* x){
......@@ -27,4 +27,3 @@ int htbl_in(hash_tbl htbl, void* x){
void htbl_destroy(hash_tbl htbl){
}
No preview for this file type
......@@ -8,6 +8,11 @@ struct cell_t {
typedef struct cell_t* list_t;
list_t list_empty(){
return NULL;
}
int list_is_empty(list_t l){
return l == NULL;
}
......
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -16,6 +16,58 @@ unsigned long int gcd(unsigned long int a, unsigned long int b){
return old_r;
}
unsigned long int f(unsigned long int x){
return(x*x+1);
}
unsigned long int rho_pollard(unsigned long int n){
unsigned long int x = 2l;
unsigned long int y = 2l;
unsigned long int d = 1l;
while(d == 1){
x = f(x) % n;
y = f(f(y)) % n;
//printf("%d, %d",x,y);
d = gcd(x-y, n);
}
return d;
}
/* -------------------------- Version Big Num ------------------------------*/
unsigned long int gcd_big(unsigned long int a, unsigned long int b){
unsigned long int old_r, r = 1;
if(a < b)
return gcd(b,a);
while(r != 0){
old_r = r;
r = a % b;
a = b;
b = r;
}
return old_r;
}
unsigned long int f_big(unsigned long int x){
return(x*x+1);
}
bignum_t rho_pollard_big(bignum_t n){
bignum_t x = 2;
bignum_t y = 2;
bignum_t d = 1;
while(d == 1){
x = f(x) % n;
y = f(f(y)) % n;
//printf("%d, %d",x,y);
d = gcd(x-y, n);
}
return d;
}
int main() {
// En utilisant l'algorithme rho de Pollard, factorisez les entiers suivants
......@@ -38,7 +90,14 @@ int main() {
bignum_sub(bignum_pow(bignum_from_int(2), bignum_from_int(2203)),
bignum_from_int(1)));
printf("%ld \n", rho_pollard(n1));
printf("%ld \n", rho_pollard(n2));
printf("%ld \n", rho_pollard(n3));
printf("%ld \n", rho_pollard(n4));
printf("%ld \n", rho_pollard(n5));
printf("%ld \n", rho_pollard(n6));
printf("%ld \n", rho_pollard(n7));
printf("%ld \n", rho_pollard(n8));
printf("PGCD(42,24) = %lu\n", gcd(42,24));
printf("PGCD(42,24) = %s\n", bignum_to_str(bignum_gcd(bignum_from_int(42),bignum_from_int(24))));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment