Skip to content
Snippets Groups Projects
Commit 75b98483 authored by Clement Delamare's avatar Clement Delamare
Browse files

TP2

parent 8e9f97eb
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
......@@ -14,7 +14,6 @@ list_t list_empty(){
//1 vrai, 0 faux
int list_is_empty(list_t l){
<<<<<<< HEAD
return l == NULL;
}
......
No preview for this file type
No preview for this file type
File added
No preview for this file type
File added
#include <stdio.h>
#include "bignum.h"
//Calcule le PGCD
unsigned long int gcd(unsigned long int a, unsigned long int b){
unsigned long int old_r, r = 1;
if(a < b)
......@@ -16,6 +17,48 @@ 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;
}
bignum_t f_bignum(bignum_t x){
bignum_t d;
d = bignum_from_int(1);
return bignum_add(bignum_mul(x,x),d);
}
unsigned long int floyd(unsigned long int n){
unsigned long int x = 145l,y =145l;
unsigned long int d=1l;
while(d==1l){
x = f(x) % n;
y = f(f(y)) % n;
//printf("%d ",x);
//printf(" %d ",y);
//printf(" %d\n", d);
d = gcd(x-y,n);
}
return d;
}
bignum_t floyd_bignum(bignum_t n){
bignum_t x, y, d, one;
x = bignum_from_int(30);
y = bignum_from_int(40);
d = bignum_from_int(1);
one = bignum_from_int(1);
while(bignum_eq(d,one)){
x = bignum_mod(f_bignum(x),n);
y = bignum_mod(f_bignum(f_bignum(y)),n);
d = bignum_gcd(bignum_sub(x,y),n);
}
bignum_destroy(x);
bignum_destroy(y);
return d;
}
int main() {
// En utilisant l'algorithme rho de Pollard, factorisez les entiers suivants
......@@ -42,6 +85,7 @@ int main() {
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("%s\n", bignum_to_str(floyd_bignum(n7)));
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment