Skip to content
Snippets Groups Projects
Commit 26d10f52 authored by Mehdy Leroux's avatar Mehdy Leroux
Browse files

fin Tp2

parent 5464b3eb
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -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;
};
......
No preview for this file type
No preview for this file type
......@@ -23,6 +23,7 @@ void test_empty() {
printf("test_empty OK\n");
}
void test_add() {
char a[] = "Coucou 1";
char b[] = "Coucou 2";
......@@ -63,13 +64,13 @@ void test_destroy() {
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;
}
......@@ -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
......@@ -38,6 +87,12 @@ 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));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment