Skip to content
Snippets Groups Projects
Commit 86d90ba6 authored by Antoine Lemaitre's avatar Antoine Lemaitre
Browse files

premier tp

parent cc6bb2ce
No related branches found
No related tags found
No related merge requests found
File added
src/bst.o 0 → 100644
File added
File added
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
struct cell_t {
void* val;
unsigned long int id;
......@@ -7,30 +11,77 @@ 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;
}
list_t list_push(list_t l, void* x){
list_t tmp = malloc(sizeof(struct cell_t));
tmp->val = x;
tmp->next = l;
if (list_is_empty(l)){
tmp->id = 1;
return tmp;
}
tmp->id = l->id+1;
return tmp;
}
list_t list_tail(list_t l){
return l->next;
}
void* list_top(list_t l){
return l->val;
}
void* list_pop(list_t* l){
if (list_is_empty(*l)){
return NULL;
}
void* list_top(list_t l){
list_t premierElement = *l;
void * val = list_top(premierElement);
*l = list_tail(premierElement);
free(premierElement);
return val;
}
void list_destroy(list_t l, void (*free)(void*)){
void list_destroy(list_t l, void (*freeVoid)(void*)){
list_t suivant;
while(l!= NULL){
suivant = list_tail(l);
freeVoid(l->val);
free(l);
l = suivant;
}
}
// return the found element or NULL
void* list_in(list_t l, void* x, int (*eq)(void*, void*)){
if (list_empty(l)){
return NULL;
}
list_t tmp = l;
while(tmp!=NULL){
if(eq(tmp->val,x)){
return tmp->val;
}
tmp = list_tail(tmp);
}
return NULL;
}
unsigned long int list_len(list_t l){
return l->id;
}
File added
File added
File added
......@@ -21,6 +21,19 @@ unsigned char md5_first_byte(const char* x){
return digest[0]; // we keep only the first byte
}
char xor(const char* x){
char digest = 0;
for(int i = 1;i<16;i++){
digest = digest ^ x[i];
}
return digest; // we keep only the first byte
}
int main(){
pair_t p, q;
list_t l;
......@@ -35,14 +48,16 @@ int main(){
for(int i = 0; i < 7; i++)
p->x[i] = rand() % (126-32-1) + 32;
p->x[7] = 0;
p->h = md5_first_byte(p->x);
//p->h = md5_first_byte(p->x);
p->h = xor(p->x);
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 MD5 first byte.\n", p->x, q->x);
//printf("%s and %s have the same MD5 first byte.\n", p->x, q->x);
return 0;
} else {
i++;
l = list_push(l, p);
}
}
......
File added
#include <assert.h>
#include <stdio.h>
#include "linked_list.h"
#include "list.h"
#include "bignum.h"
void test_emptyness() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment