Skip to content
Snippets Groups Projects
Commit 8e86c38e authored by Antoine Priou's avatar Antoine Priou
Browse files

tp2

parent 33cd946b
Branches main
No related tags found
No related merge requests found
......@@ -14,9 +14,8 @@ 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){
......@@ -27,4 +26,4 @@ int htbl_in(hash_tbl htbl, void* x){
void htbl_destroy(hash_tbl htbl){
}
*/
......@@ -23,6 +23,7 @@ void test_empty() {
printf("test_empty OK\n");
}
/*
void test_add() {
char a[] = "Coucou 1";
char b[] = "Coucou 2";
......@@ -62,14 +63,14 @@ void test_destroy() {
htbl_destroy(htbl);
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;
}
......@@ -62,6 +62,7 @@ void test_top(){
}
void test_pop(){
bignum_t x,y,z;
list_t l;
......@@ -84,6 +85,7 @@ void test_pop(){
printf("test_pop OK\n");
}
void test_in_list(){
bignum_t x,y,z;
list_t l;
......
......@@ -16,6 +16,35 @@ unsigned long int gcd(unsigned long int a, unsigned long int b){
return old_r;
}
int f(long int x){
return (x*x+1) ; }
bignum_t fB (bignum_t x){
return bignum_add(bignum_mul(x, x), bignum_from_int(1)) ; }
unsigned long int TP(unsigned long int n){
unsigned long int x = 2l ;
unsigned long int y = 2l ;
unsigned long int z = 1l ;
while (z == 1){
x = (f(x)) % n ;
y = f( f(y) ) % n ;
z = gcd(x-y, n) ; }
return z ;
}
bignum_t TPbigNum(bignum_t n){
bignum_t x = bignum_from_int(2) ;
bignum_t y = bignum_from_int(2) ;
bignum_t z = bignum_from_int(1) ;
while (z == bignum_from_int(1) ){
x = bignum_mod( (fB(x)), n) ;
y = bignum_mod( fB( fB(y) ), n) ;
z = bignum_gcd(bignum_sub(x, y), n) ; }
return z ;
}
int main() {
// En utilisant l'algorithme rho de Pollard, factorisez les entiers suivants
......@@ -25,12 +54,29 @@ int main() {
unsigned long int n4 = 15241 * 18119;
unsigned long int n5 = 366127l * 416797l;
unsigned long int n6 = 15651941l * 15485863l;
unsigned long int menfou = 16128 * 3720 ;
printf("%lu %lu %lu %lu %lu %lu \n", n1, n2, n3, n4, n5, n6);
printf("\n Fonction : \n");
printf("%lu \n", TP(n1));
printf("%lu \n", TP(n2));
printf("%lu \n", TP(n3));
printf("%lu \n", TP(n4));
printf("%lu \n", TP(n5));
printf("%lu \n", TP(menfou));
bignum_t n7, n8;
n7 = bignum_mul(bignum_sub(bignum_pow(bignum_from_int(2), bignum_from_int(127)),
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_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)),
......@@ -38,10 +84,11 @@ int main() {
bignum_sub(bignum_pow(bignum_from_int(2), bignum_from_int(2203)),
bignum_from_int(1)));
printf("oulah \n");
printf("%lu \n", TPbigNum(n7));
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))));
printf("PGCD(42,24) = %s\n \n", bignum_to_str(bignum_gcd(bignum_from_int(42),bignum_from_int(24))));
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment