Discuss prime numbers in the C Programming forum on Dev Shed. prime numbers C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
prime numbers
Hello
I´d like to know if u can help figure out a way to find large prime numbers in other to create the private and public keys on a RSA system.
The user types in a number(20 digit) and if it isnt prime, I´m supposed to find the closest prime to the number given.
I also dont know how I´m suppose to store these numbers because they´re pretty large and I dont know how work w/them.
I´d really appreciate if u could help me,
thanks
Posts: 18
Time spent in forums: 24 m 31 sec
Reputation Power: 0
I think you need use some functions from openssl library - bn.h (big interger objects), try bn.h on google, actually it's will be difficult without any expirience with openssl library.
One of the functions provided by then bn.h (BN package) BN_generate_prime
Posts: 18
Time spent in forums: 24 m 31 sec
Reputation Power: 0
Quote:
Originally Posted by Juliaa
Hello
I´d like to know if u can help figure out a way to find large prime numbers in other to create the private and public keys on a RSA system.
The user types in a number(20 digit) and if it isnt prime, I´m supposed to find the closest prime to the number given.
I also dont know how I´m suppose to store these numbers because they´re pretty large and I dont know how work w/them.
I´d really appreciate if u could help me,
thanks
I write example for you:
- prerequest: installed openssl library
Code:
#include <stdio.h>
/*openssl library includes*/
#include <openssl/bn.h>
#include <openssl/ssl.h>
/*function definitions*/
static void prime_status(int code, int arg, void *cb_arg);
BIGNUM *generate_prime(int bits, int safe);
/*show prime status - callback*/
static void prime_status(int code, int arg, void *cb_arg)
{
if (code==0)
fprintf(stderr, "\n * Found potential prime #%d ... ", (arg + 1));
else if (code == 1 && arg && !(arg % 10))
fprintf(stderr, ".");
else
fprintf(stderr, "\nGot one !\n");
}
/*generate prime - bits, safe*/
BIGNUM *generate_prime(int bits, int safe)
{
char *string;
BIGNUM *prime;
fprintf(stderr, "Searching from a %sprime %d bits in size ...", (safe ? "safe" : ""), bits);
/*generate prime*/
prime=BN_generate_prime(NULL, bits, safe, NULL, NULL, prime_status, NULL);
/*if not generated, return NULL pointer*/
if(!prime)
return NULL;
/*convert big number to decimal*/
string=BN_bn2dec(prime);
/*show result*/
if(string)
{
fprintf(stderr, "Found prime: %s\n", string);
OPENSSL_free(string);
}
return prime;
}
int main()
{
/*pointer on BIGNUM*/
BIGNUM *bn;
/*allocate an initialize a new BIGNUM - dynamicaly*/
bn=BN_new();
/*get big number - prime, 100-bits 10-safe*/
/*CHANGE THIS VALUES*/
if((bn = generate_prime(100, 100)) == NULL)
{
fprintf(stderr, "Can't generate prime !!!\n");
return -3;
}
/*free memory*/
BN_free(bn);
return 1;
}
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you for ur help, but do u know if there's another library that I can use w/ dev-c++(Windows) because I was looking at the openSSL and it loooked really helpful but it only works w/ Linux, right?
Posts: 18
Time spent in forums: 24 m 31 sec
Reputation Power: 0
Quote:
Originally Posted by Juliaa
Thank you for ur help, but do u know if there's another library that I can use w/ dev-c++(Windows) because I was looking at the openSSL and it loooked really helpful but it only works w/ Linux, right?