Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:21:24+00:00 2026-06-04T20:21:24+00:00

I have implemented the RSA algorithm in C++, the program is working however the

  • 0

I have implemented the RSA algorithm in C++, the program is working however the srand calls are making the program slow. I have used srand for generating the two prime numbers and the encryption key (e). Here’s the snippet

...............................................
do
{
    p = make_prime_number();
    q = make_prime_number();
}while(p == q);

phi = (p - 1) * (q - 1);
n = p * q;

do
{
    e = random_builder (20);

    int *t = extended_gcd (e, phi);
    d = t[0];
}while(gcd(e, phi) != 1 || d < 1 || d >= n );
...............................................

int random_builder(const int max)
{
    srand(time(NULL));

    return rand() % max + 1;
}

bool is_prime(const int num)
{
    for(int i = 2; i <= num/2; i++)
        if(num % i == 0) 
            return false;

    return true;
}

int make_prime_number()
{
    int num;

    do
    {
        num = random_builder(20);
    }while(not is_prime(num));

    return num;
}

Can we somehow speed up the process by modifying the seed in srand ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:21:25+00:00Added an answer on June 4, 2026 at 8:21 pm

    There is no need to call srand() more than once. Call it once at the start of your program, and then leave it alone.

    After calling srand() with a specific seed value, the same sequence of random numbers is generated by rand(). Therefore, since you are calling with the current time in seconds, your random_builder() function only returns a different value once every second.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented Solr search in one of my .net application. Everything working fine
I have implemented a custom allocator (to be used by STL containers within my
I have implemented quartz scheduler in my application. And its working upto a certain
I'm looking for a fast asymmetric cypher algorithm to be used in C++ program.
I have implemented clustering using Elasticsearch. ElasticHead UI displays detected nodes. However I am
I have a private key and exponent, i need to implement RSA encryption of
I have implemented the usual examples of accessing the camera roll on ipad and
I have implemented Twitter4J in my Android application and it's works fine. But after
I have implemented a jquery ui autocomplete with data from database. Right now what
I have implemented SSO authentication using the sourceforge spnego project . This is my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.