Loading tests/list_tests.c +4 −4 Original line number Diff line number Diff line #include <assert.h> #include <stdio.h> #include <string.h> #include "list.h" #include "bignum.h" Loading Loading @@ -40,7 +41,7 @@ void test_push(){ printf("test_push OK\n"); } /* void test_top(){ bignum_t x,y,z; list_t l; Loading Loading @@ -106,16 +107,15 @@ void test_in_list(){ list_destroy(l, &destroy); printf("test_in_list OK\n"); } */ int main() { printf("=== LIST tests ===\n"); test_emptyness(); /* test_push(); test_top(); test_pop(); test_in_list(); */ return 0; } tests/prod_collisions.c 0 → 100644 +52 −0 Original line number Diff line number Diff line #include <stdlib.h> #include <stdio.h> #include <time.h> #include <openssl/md5.h> #include "list.h" typedef struct pair_t { char x[16]; long int h; }* pair_t; int eq_pair(void* a, void* b){ return ((pair_t)a)->h == ((pair_t)b)->h; } /* char x[16] */ long int prod(char* x,int taille){ long int res = 1; for(int i = 0; i< taille-1; i++){ res = res*x[i]; } return res; } int main(){ pair_t p, q; list_t l; unsigned int i = 0; srand(time(NULL)); l = list_empty(); for(;;){ p = (pair_t)malloc(sizeof(struct pair_t)); for(int i = 0; i < 15; i++) p->x[i] = rand() % (126-32-1) + 32; p->x[15] = 0; p->h = prod(p->x,16); if((q = (pair_t)list_in(l, p, eq_pair)) != NULL){ printf("After %d iterations, a collision happened !\n", i); printf("%s and %s have the same produit.\n", p->x, q->x); return 0; } else { i++; l = list_push(l, p); } } } tests/sum_collision.c 0 → 100644 +52 −0 Original line number Diff line number Diff line #include <stdlib.h> #include <stdio.h> #include <time.h> #include <openssl/md5.h> #include "list.h" typedef struct pair_t { char x[16]; unsigned char h; }* pair_t; int eq_pair(void* a, void* b){ return ((pair_t)a)->h == ((pair_t)b)->h; } /* char x[16] */ int sum(const char* x,int taille){ int res = 0; for(int i=0; i< taille; i++){ res = res+x[i]; } return res; } int main(){ pair_t p, q; list_t l; unsigned int i = 0; srand(time(NULL)); l = list_empty(); for(;;){ p = (pair_t)malloc(sizeof(struct pair_t)); for(int i = 0; i < 16; i++) p->x[i] = rand() % (126-32-1) + 32; p->x[15] = 0; p->h = sum(p->x,16); if((q = (pair_t)list_in(l, p, eq_pair)) != NULL){ printf("After %d iterations, a collision happened !\n", i); printf("%s and %s have the same sum.\n", p->x, q->x); return 0; } else { i++; l = list_push(l, p); } } } tests/xor_collision.c 0 → 100644 +52 −0 Original line number Diff line number Diff line #include <stdlib.h> #include <stdio.h> #include <time.h> #include <openssl/md5.h> #include "list.h" typedef struct pair_t { char x[16]; unsigned char h; }* pair_t; int eq_pair(void* a, void* b){ return ((pair_t)a)->h == ((pair_t)b)->h; } /* char x[16] */ int xor(const char* x,int taille){ int res = 0; for(int i=0; i< taille; i++){ res = res^x[i]; } return res; } int main(){ pair_t p, q; list_t l; unsigned int i = 0; srand(time(NULL)); l = list_empty(); for(;;){ p = (pair_t)malloc(sizeof(struct pair_t)); for(int i = 0; i < 7; i++) p->x[i] = rand() % (126-32-1) + 32; p->x[15] = 0; p->h = xor(p->x,16); if((q = (pair_t)list_in(l, p, eq_pair)) != NULL){ printf("After %d iterations, a collision happened !\n", i); printf("%s and %s have the same xor.\n", p->x, q->x); return 0; } else { i++; l = list_push(l, p); } } } Loading
tests/list_tests.c +4 −4 Original line number Diff line number Diff line #include <assert.h> #include <stdio.h> #include <string.h> #include "list.h" #include "bignum.h" Loading Loading @@ -40,7 +41,7 @@ void test_push(){ printf("test_push OK\n"); } /* void test_top(){ bignum_t x,y,z; list_t l; Loading Loading @@ -106,16 +107,15 @@ void test_in_list(){ list_destroy(l, &destroy); printf("test_in_list OK\n"); } */ int main() { printf("=== LIST tests ===\n"); test_emptyness(); /* test_push(); test_top(); test_pop(); test_in_list(); */ return 0; }
tests/prod_collisions.c 0 → 100644 +52 −0 Original line number Diff line number Diff line #include <stdlib.h> #include <stdio.h> #include <time.h> #include <openssl/md5.h> #include "list.h" typedef struct pair_t { char x[16]; long int h; }* pair_t; int eq_pair(void* a, void* b){ return ((pair_t)a)->h == ((pair_t)b)->h; } /* char x[16] */ long int prod(char* x,int taille){ long int res = 1; for(int i = 0; i< taille-1; i++){ res = res*x[i]; } return res; } int main(){ pair_t p, q; list_t l; unsigned int i = 0; srand(time(NULL)); l = list_empty(); for(;;){ p = (pair_t)malloc(sizeof(struct pair_t)); for(int i = 0; i < 15; i++) p->x[i] = rand() % (126-32-1) + 32; p->x[15] = 0; p->h = prod(p->x,16); if((q = (pair_t)list_in(l, p, eq_pair)) != NULL){ printf("After %d iterations, a collision happened !\n", i); printf("%s and %s have the same produit.\n", p->x, q->x); return 0; } else { i++; l = list_push(l, p); } } }
tests/sum_collision.c 0 → 100644 +52 −0 Original line number Diff line number Diff line #include <stdlib.h> #include <stdio.h> #include <time.h> #include <openssl/md5.h> #include "list.h" typedef struct pair_t { char x[16]; unsigned char h; }* pair_t; int eq_pair(void* a, void* b){ return ((pair_t)a)->h == ((pair_t)b)->h; } /* char x[16] */ int sum(const char* x,int taille){ int res = 0; for(int i=0; i< taille; i++){ res = res+x[i]; } return res; } int main(){ pair_t p, q; list_t l; unsigned int i = 0; srand(time(NULL)); l = list_empty(); for(;;){ p = (pair_t)malloc(sizeof(struct pair_t)); for(int i = 0; i < 16; i++) p->x[i] = rand() % (126-32-1) + 32; p->x[15] = 0; p->h = sum(p->x,16); if((q = (pair_t)list_in(l, p, eq_pair)) != NULL){ printf("After %d iterations, a collision happened !\n", i); printf("%s and %s have the same sum.\n", p->x, q->x); return 0; } else { i++; l = list_push(l, p); } } }
tests/xor_collision.c 0 → 100644 +52 −0 Original line number Diff line number Diff line #include <stdlib.h> #include <stdio.h> #include <time.h> #include <openssl/md5.h> #include "list.h" typedef struct pair_t { char x[16]; unsigned char h; }* pair_t; int eq_pair(void* a, void* b){ return ((pair_t)a)->h == ((pair_t)b)->h; } /* char x[16] */ int xor(const char* x,int taille){ int res = 0; for(int i=0; i< taille; i++){ res = res^x[i]; } return res; } int main(){ pair_t p, q; list_t l; unsigned int i = 0; srand(time(NULL)); l = list_empty(); for(;;){ p = (pair_t)malloc(sizeof(struct pair_t)); for(int i = 0; i < 7; i++) p->x[i] = rand() % (126-32-1) + 32; p->x[15] = 0; p->h = xor(p->x,16); if((q = (pair_t)list_in(l, p, eq_pair)) != NULL){ printf("After %d iterations, a collision happened !\n", i); printf("%s and %s have the same xor.\n", p->x, q->x); return 0; } else { i++; l = list_push(l, p); } } }