1024bits / c++

Fermé
emnaisecs - 24 mai 2012 à 17:08
Char Snipeur Messages postés 9696 Date d'inscription vendredi 23 avril 2004 Statut Contributeur Dernière intervention 3 octobre 2023 - 25 mai 2012 à 12:05
Bonjour,


pouvez-vous m'aider a trouver un algorithme qui peut choisir aléatroirement des nombres premiers de 1024 bits j'ai écris ce programme mais les nompbres sont de petite taille
long long x=1,y=a; // long long is taken to avoid overflow of intermediate results
while(b > 0)
{
if(b%2 == 1)
{
x=(x*y)%c;
}
y = (y*y)%c; // squaring the base
b /= 2;
}
return x%c;
}

unsigned long long myRandom(void)
{
static int first = 0;

if (first == 0)
{
unsigned long long t = (unsigned long long) time(NULL);
srand(t);
first = 1;
}
return ( rand () % 10 );
}
bool Miller(long long pq,int iteration){
if(pq<2)
{
return false;
}
if(pq!=2 && pq%2==0)
{
return false;
}
long long s=pq-1;
while(s%2==0)
{
s/=2;
}
for(int i=0;i<iteration;i++)
{
long long a=rand()%(pq-1)+1,
temp=s;
long long mod=modulo(a,temp,pq);
while(temp!=pq-1 && mod!=1 && mod!=pq-1)
{
mod=mod*mod%pq;
temp *= 2;
}
if(mod!=pq-1 && temp%2==0)
{
return false;
}
}
return true;

1 réponse

Char Snipeur Messages postés 9696 Date d'inscription vendredi 23 avril 2004 Statut Contributeur Dernière intervention 3 octobre 2023 1 297
25 mai 2012 à 12:05
Si tu veux faire ça il faut une bibliothèque spéciale
0