Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Blum Blum Shub

Blum Blum Shub

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
22 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Member_14956475

    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 :)

    M Offline
    M Offline
    Member_14956475
    wrote on last edited by
    #21

    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

    L 1 Reply Last reply
    0
    • M Member_14956475

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #22

      That should already work, but you can add another set of parenthesis to make sure:

      x[i] = (rand() * (x[i-1] * x[i-1])) % M;

      So the random number times the square of x[i-1] should be calculated first.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups