Loading tests/htbl_tests.c 0 → 100644 +75 −0 Changes for tests/htbl_tests.c: 75 added lines, 0 removed lines. Original line number Diff line number Diff line #include <stdio.h> #include <stdlib.h> #include <assert.h> #include "hash_tbl.h" // char* val size_t hash(void* val){ return (*((char*) val)) & ((1<<5) - 1); } int eq(void* a, void* b){ char* aa = (char*) a; char* bb = (char*) b; for(int i = 0; i <16; i++) if(aa[i] != bb[i]) return 0; return 1; } void test_empty() { hash_tbl htbl = htbl_empty(&hash, &eq, &free); assert(htbl->size == 0); printf("test_empty OK\n"); } void test_add() { char a[] = "Coucou 1"; char b[] = "Coucou 2"; hash_tbl htbl = htbl_empty(&hash, &eq, &free); htbl_add(htbl, a); assert(htbl->size == 1); assert(list_in(htbl->array[hash(a)], a, &eq)); htbl_add(htbl, a); assert(htbl->size == 1); assert(list_in(htbl->array[hash(a)], a, &eq)); htbl_add(htbl, b); assert(htbl->size == 2); assert(list_in(htbl->array[hash(a)], a, &eq)); assert(list_in(htbl->array[hash(b)], b, &eq)); printf("test_add OK\n"); } void test_in() { char a[] = "Coucou 1"; char b[] = "Coucou 2"; hash_tbl htbl = htbl_empty(&hash, &eq, &free); htbl_add(htbl, a); assert(htbl_in(htbl, a)); assert(!htbl_in(htbl, b)); htbl_add(htbl, b); assert(htbl_in(htbl, a)); assert(htbl_in(htbl, b)); printf("test_in OK\n"); } void test_destroy() { char a[] = "Coucou 1"; char b[] = "Coucou 2"; hash_tbl htbl = htbl_empty(&hash, &eq, &free); htbl_add(htbl, a); htbl_add(htbl, b); htbl_destroy(htbl); printf("test_destroy OK\n"); } int main() { printf("=== HTBL tests ===\n"); test_empty(); test_add(); test_in(); test_destroy(); return 0; } tests/rho_pollard.c 0 → 100644 +47 −0 Changes for tests/rho_pollard.c: 47 added lines, 0 removed lines. Original line number Diff line number Diff line #include <stdio.h> #include "bignum.h" unsigned long int gcd(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; } 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)), bignum_from_int(1))); n8 = bignum_mul(bignum_sub(bignum_pow(bignum_from_int(2), bignum_from_int(607)), bignum_from_int(1)), bignum_sub(bignum_pow(bignum_from_int(2), bignum_from_int(2203)), 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)))); return 0; } Loading
tests/htbl_tests.c 0 → 100644 +75 −0 Changes for tests/htbl_tests.c: 75 added lines, 0 removed lines. Original line number Diff line number Diff line #include <stdio.h> #include <stdlib.h> #include <assert.h> #include "hash_tbl.h" // char* val size_t hash(void* val){ return (*((char*) val)) & ((1<<5) - 1); } int eq(void* a, void* b){ char* aa = (char*) a; char* bb = (char*) b; for(int i = 0; i <16; i++) if(aa[i] != bb[i]) return 0; return 1; } void test_empty() { hash_tbl htbl = htbl_empty(&hash, &eq, &free); assert(htbl->size == 0); printf("test_empty OK\n"); } void test_add() { char a[] = "Coucou 1"; char b[] = "Coucou 2"; hash_tbl htbl = htbl_empty(&hash, &eq, &free); htbl_add(htbl, a); assert(htbl->size == 1); assert(list_in(htbl->array[hash(a)], a, &eq)); htbl_add(htbl, a); assert(htbl->size == 1); assert(list_in(htbl->array[hash(a)], a, &eq)); htbl_add(htbl, b); assert(htbl->size == 2); assert(list_in(htbl->array[hash(a)], a, &eq)); assert(list_in(htbl->array[hash(b)], b, &eq)); printf("test_add OK\n"); } void test_in() { char a[] = "Coucou 1"; char b[] = "Coucou 2"; hash_tbl htbl = htbl_empty(&hash, &eq, &free); htbl_add(htbl, a); assert(htbl_in(htbl, a)); assert(!htbl_in(htbl, b)); htbl_add(htbl, b); assert(htbl_in(htbl, a)); assert(htbl_in(htbl, b)); printf("test_in OK\n"); } void test_destroy() { char a[] = "Coucou 1"; char b[] = "Coucou 2"; hash_tbl htbl = htbl_empty(&hash, &eq, &free); htbl_add(htbl, a); htbl_add(htbl, b); htbl_destroy(htbl); printf("test_destroy OK\n"); } int main() { printf("=== HTBL tests ===\n"); test_empty(); test_add(); test_in(); test_destroy(); return 0; }
tests/rho_pollard.c 0 → 100644 +47 −0 Changes for tests/rho_pollard.c: 47 added lines, 0 removed lines. Original line number Diff line number Diff line #include <stdio.h> #include "bignum.h" unsigned long int gcd(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; } 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)), bignum_from_int(1))); n8 = bignum_mul(bignum_sub(bignum_pow(bignum_from_int(2), bignum_from_int(607)), bignum_from_int(1)), bignum_sub(bignum_pow(bignum_from_int(2), bignum_from_int(2203)), 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)))); return 0; }