diff --git a/src/bignum.o b/src/bignum.o index 1e09dd6fd3cf32ef836afbc17a30e8017f0269e7..002a9833acb4c35f6fa552fbed5b673dd2677802 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 8b2fef8617968c9a6ee74abceb5eb8ef8ea9a659..ed1543d14496ebd2cee80421a37b7452b05dfa75 100644 --- a/src/hash_tbl.c +++ b/src/hash_tbl.c @@ -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){ } - diff --git a/src/hash_tbl.o b/src/hash_tbl.o index a4185b4783fb5781bec1e0d4529cc6feb10f2382..0ac7139dd6dcb958fa8c0bb43a97a56c4696f212 100644 Binary files a/src/hash_tbl.o and b/src/hash_tbl.o differ diff --git a/src/list.c b/src/list.c index a8d696c19035c42e67db47bb34048cef2f7bdddc..8d596a19666e7bec7a0e423ce4a7363a20f4820d 100644 --- a/src/list.c +++ b/src/list.c @@ -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; } diff --git a/src/list.o b/src/list.o index a055b9e4682acdf3408274f8eafc491a0838ceed..e78eea9098d455967c47be84f76e8fddd8f7ab17 100644 Binary files a/src/list.o and b/src/list.o differ diff --git a/tests/bignum_tests b/tests/bignum_tests index b5bb74f72f430b046a23fcea51c65769ad765088..dd91ec6d69ab337bb33d4538f7cb7d49b8da14b6 100755 Binary files a/tests/bignum_tests and b/tests/bignum_tests differ diff --git a/tests/list_tests b/tests/list_tests index 4fc991488e811b1d49d5b9f89216192e2e97918f..c4b182ba450fe4aed46adab6b803f00a1b345914 100755 Binary files a/tests/list_tests and b/tests/list_tests differ diff --git a/tests/rho_pollard.c b/tests/rho_pollard.c index de3d18aee2ce8785fbcbf914ed3880bd85f88a2e..d5d113ec78cb90b26fea2f7cd366a3b39dd4a622 100644 --- a/tests/rho_pollard.c +++ b/tests/rho_pollard.c @@ -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 @@ -27,7 +79,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 +90,17 @@ 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)))); - + return 0; }