diff --git a/src/bignum.o b/src/bignum.o index 467ffb17e5c40872c4cc201cf28ed32e69b9289a..1c46d089cad0837311331a1bc2e790eb3c8d8b57 100644 Binary files a/src/bignum.o and b/src/bignum.o differ diff --git a/src/hash_tbl.c b/src/hash_tbl.c index 27421d003331a03ec5f1ca5f1f49ae25cc495519..91f1b8ce5daff37e9cba179ea765165f1310c302 100644 --- a/src/hash_tbl.c +++ b/src/hash_tbl.c @@ -8,7 +8,6 @@ struct hash_tbl { int (*eq)(void*, void*); void (*free)(void*); unsigned long int size; - unsigned long int capacity; size_t capacity; // array length list_t* array; }; diff --git a/src/hash_tbl.o b/src/hash_tbl.o index 56354d5beb37b98cd621bbef99d5f834474f909c..0f86b20d6868f49f5cf8b2892055390df05cc273 100644 Binary files a/src/hash_tbl.o and b/src/hash_tbl.o differ diff --git a/src/list.o b/src/list.o index 88bda8f3337c0bbe8cc6e2b1a799f697edc15556..0c67936a4bfdd2003cf337723b4c50549f40f1e1 100644 Binary files a/src/list.o and b/src/list.o differ diff --git a/tests/htbl_tests.c b/tests/htbl_tests.c index 325c52145a55ff57b4c9ece564a8ea4b5fdb4a17..ad93ab6c46350ab807b99f4f17d9a3a5900f76dd 100644 --- a/tests/htbl_tests.c +++ b/tests/htbl_tests.c @@ -23,6 +23,7 @@ void test_empty() { printf("test_empty OK\n"); } + void test_add() { char a[] = "Coucou 1"; char b[] = "Coucou 2"; @@ -50,7 +51,7 @@ void test_in() { htbl_add(htbl, b); assert(htbl_in(htbl, a)); assert(htbl_in(htbl, b)); - printf("test_in OK\n"); + printf("test_in OK\n"); } void test_destroy() { @@ -60,16 +61,16 @@ void test_destroy() { htbl_add(htbl, a); htbl_add(htbl, b); htbl_destroy(htbl); - printf("test_destroy OK\n"); + printf("test_destroy OK\n"); } + int main() { printf("=== HTBL tests ===\n"); test_empty(); - test_add(); - test_in(); - test_destroy(); + //test_add(); + //test_in(); + //test_destroy(); return 0; } - diff --git a/tests/rho_pollard.c b/tests/rho_pollard.c index de3d18aee2ce8785fbcbf914ed3880bd85f88a2e..377054fbb7c28e79fcc20a19ccdbeae2af33a866 100644 --- a/tests/rho_pollard.c +++ b/tests/rho_pollard.c @@ -16,6 +16,55 @@ 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; +} + +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 % d; + 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 @@ -27,7 +76,7 @@ int main() { 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)), @@ -38,10 +87,16 @@ 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("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)))); - + return 0; }