I am implementing the RSA algorithm for encryption and decryption as given here:
http://www.di-mgt.com.au/rsa_alg.html
But could not understand the random pr
Following the practical notes at the end of the linked page you would arrive at something like this for the prime generation:
unsigned int get_prime(int e)
{
while (true)
{
unsigned int suspect = 1 + (unsigned int)(65535.0 * rand() / (RAND_MAX + 1.0));
suspect &= 0x0000FFFF; // make sure only the lower 16bit are set
suspect |= 0xC001; // set the two highest and the lowest bit
while (!test_prime(suspect))
{
suspect += 2;
}
if (suspect < 65536 && gcd(e, suspect - 1) == 1)
return suspect;
}
}
test_prime is supposed to be an implementation of the Miller-Rabin test. The function above makes certain assumptions and has some drawbacks:
int is 32 bitrand() is usually not a good random number generator to use for serious encryptionDon't use this in any production code.
According to the article it seems ok to choose e fixed.