Blum Blum Shub
-
Hi everyone . I am a newbie in programming , so i would be very grateful if you could help me . I have to implement the Blum Blum Shub in C or C++ using the stdlib.h and time.h libraries . Can anyone help me with this ? Thanks :)
Okay , so this is the final code that i have at the moment #include #include #include /*BLUM BLUM SHUB*/ int main () { const int p = 347; const int q = 351; const unsigned long long int s = 12373273; int N ; printf("Introdu numarul de cifre aleatorii:"); scanf("%i", &N); unsigned int i,M,x[N]; srand(time(NULL)); M=p*q; i=0; x[0]=s; FILE *fp; //txt code fp = fopen("file.txt", "w"); //txt code for(i=1;i<=N;i++){ x[i]=rand()*(x[i-1]*x[i-1])%M; } for(i=1;i<=N;i++){ printf("%d\t",x[i]); fprintf(fp, "%d ",x[i]); //txt code } system("PAUSE"); fclose(fp);//txt code return 0; } It's working but i have one issue that i can't still solve , i need to put a maximal limit of the generated numbers at input , can anyone give me a clue how i can set x[i] a limit? I only found how to put a limit at rand but when it multiplies with function of BBS it exceeds the limit
-
Okay , so this is the final code that i have at the moment #include #include #include /*BLUM BLUM SHUB*/ int main () { const int p = 347; const int q = 351; const unsigned long long int s = 12373273; int N ; printf("Introdu numarul de cifre aleatorii:"); scanf("%i", &N); unsigned int i,M,x[N]; srand(time(NULL)); M=p*q; i=0; x[0]=s; FILE *fp; //txt code fp = fopen("file.txt", "w"); //txt code for(i=1;i<=N;i++){ x[i]=rand()*(x[i-1]*x[i-1])%M; } for(i=1;i<=N;i++){ printf("%d\t",x[i]); fprintf(fp, "%d ",x[i]); //txt code } system("PAUSE"); fclose(fp);//txt code return 0; } It's working but i have one issue that i can't still solve , i need to put a maximal limit of the generated numbers at input , can anyone give me a clue how i can set x[i] a limit? I only found how to put a limit at rand but when it multiplies with function of BBS it exceeds the limit