diff --git a/src/list.c b/src/list.c index 316d052e51dfd87ffd2bc59469d37538bed5536a..ce2e1a7f6ba7bba45f28e3971f5090dd36cd9e64 100644 --- a/src/list.c +++ b/src/list.c @@ -33,7 +33,6 @@ void* list_pop(list_t* l){ return NULL; list_t new_head = (*l)->next; void* res = (*l)->val; ->>>>>>> prof/main free(*l); *l = new_head; return res; @@ -41,7 +40,6 @@ void* list_pop(list_t* l){ void* list_top(list_t l){ return list_is_empty(l) ? NULL : l->val; ->>>>>>> prof/main } void list_destroy(list_t l, void (*free)(void*)){ @@ -61,5 +59,4 @@ void* list_in(list_t l, void* x, int (*eq)(void*, void*)){ unsigned long int list_len(list_t l){ return list_is_empty(l) ? 0 : l->id; ->>>>>>> prof/main } diff --git a/tests/rho_pollard.c b/tests/rho_pollard.c index de3d18aee2ce8785fbcbf914ed3880bd85f88a2e..9f4c697a9e11c765697cb8b6cc928f441faff007 100644 --- a/tests/rho_pollard.c +++ b/tests/rho_pollard.c @@ -16,18 +16,58 @@ unsigned long int gcd(unsigned long int a, unsigned long int b){ return old_r; } +unsigned long int f(unsigned long x){ + return x*x + 1; +} + +unsigned long int Pollard(unsigned long n){ + unsigned long int x = 2l; + unsigned long int y = 2l; + unsigned long int d = 1l; + while(d==1l){ + x = f(x)%n; + y = f(f(y))%n; + d = gcd(x-y, n); + } + return d; +} + + +bignum_t Pollard2(bignum_t n){ + bignum_t f2(bignum_t x){ + return bignum_pow(x,2) + 1; + } + unsigned long int x1 = 2l; + unsigned long int y2 = 2l; + unsigned long int d3 = 1l; + + bignum_t x = bignum_from_int(x1); + bignum_t y = bignum_from_int(y2); + bignum_t d = bignum_from_int(d3); + + while(d == bignum_from_int(1l)){ + x = bignum_mod(f2(x),n); + y = bignum_mod(f2(f2(y)),n); + d = gcd(x-y, n); + } + return d; +} + + int main() { // En utilisant l'algorithme rho de Pollard, factorisez les entiers suivants unsigned long int n1 = 17 * 113; + unsigned long int n2 = 239 * 431; unsigned long int n3 = 3469 * 4363; unsigned long int n4 = 15241 * 18119; + unsigned long int n5 = 366127l * 416797l; unsigned long int n6 = 15651941l * 15485863l; bignum_t n7, n8; - + n7 = bignum_mul(bignum_sub(bignum_pow(bignum_from_int(2), bignum_from_int(127)), bignum_from_int(1)), bignum_sub(bignum_pow(bignum_from_int(2), bignum_from_int(61)), @@ -39,9 +79,16 @@ int main() { bignum_from_int(1))); - + 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)))); - + printf("Pollard n1 = %ld\n", Pollard(n1)); + printf("Pollard n2 = %ld\n", Pollard(n2)); + printf("Pollard n3 = %ld\n", Pollard(n3)); + printf("Pollard n4 = %ld\n", Pollard(n4)); + printf("Pollard n5 = %ld\n", Pollard(n5)); + printf("Pollard n6 = %ld\n", Pollard(n6)); + printf("Pollard n7 = %d\n", bignum_to_str(Pollard2(n7))); + printf("Pollard n8 = %ld\n", Pollard(n8)); return 0; }