C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 5th, 2004, 10:10 AM
Juliaa Juliaa is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Brazil
Posts: 3 Juliaa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb 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

Reply With Quote
  #2  
Old August 5th, 2004, 10:23 AM
f3x f3x is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 18 f3x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

http://www.openssl.org/docs/crypto/...rate_prime.html

As it’s name implies, the function generates prime numbers, but more importantly, it generates pseudorandom primes.

I guess you can find examples on:

http://openssl.org

Reply With Quote
  #3  
Old August 5th, 2004, 11:23 AM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 5 h 20 m 41 sec
Reputation Power: 48
Here some programs (source) for finding and testing primality:

http://primes.utm.edu/links/programs/seeking_large_primes/

Reply With Quote
  #4  
Old August 5th, 2004, 11:25 AM
f3x f3x is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 18 f3x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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;
}


To compile:

gcc -o prime prime.c -lcrypto

Reply With Quote
  #5  
Old August 5th, 2004, 09:51 PM
Juliaa Juliaa is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Brazil
Posts: 3 Juliaa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Arrow

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?

Reply With Quote
  #6  
Old August 6th, 2004, 02:57 AM
f3x f3x is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 18 f3x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?


Pointer to Openssl library for Windows:

Openssl for Windows

download and install

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > prime numbers


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT