LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-12-2004, 02:39 PM   #1
jpc82
Member
 
Registered: Oct 2001
Distribution: Gentoo
Posts: 140

Rep: Reputation: 15
int value larger then unsigned long


For my number theory class we need to implement a public key encryption program which I have done, however I'm runing into some problems when I try to use larger key values.

Basically this is the problem code

for(i = 1; i <= b; i++)
{
value = value * a;
while(value >= n)
{
value = value - n;
}
}



My problem is in the line
value = value * a;

Now as soon as I do that the number overflows and I get invalid results, before I can bring bring it down into range.

So my question is basically is the a variable larger then an unsigned long? Some of my class mates used java which has something called bigint, which is only limited by your ram. Is there anything like this with c, or at least a 64bit int value?
 
Old 03-12-2004, 02:51 PM   #2
andzerger
Member
 
Registered: Feb 2004
Location: denver
Distribution: slackware && freeBSD && rh9
Posts: 92

Rep: Reputation: 15
hmm, ill bet there is a better way to do it but heres my hack
start with a character array of whatever size, then parse it character by character
 
Old 03-12-2004, 03:29 PM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
some choices:

unsigned long long datatype gives you 2^64 -1 which is very small for cryptography.

Or you can use one of the extended precision libraries like gmp from gnu.
Most crypto apps use one of these. mpi is another extended precision library.

Last edited by jim mcnamara; 03-12-2004 at 03:33 PM.
 
Old 03-12-2004, 03:54 PM   #4
jpc82
Member
 
Registered: Oct 2001
Distribution: Gentoo
Posts: 140

Original Poster
Rep: Reputation: 15
If your right and unsigned long long is 2^64 -1 thats exactly what I need. I'm trying to search the web right now to confirm.

I know that 2^64 -1 is very small, but this project is not about making a secure public key encryption. What we are learning is how number theory is used for encrypion, and why its needed to do it, and why its so hard to crack.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
printf unsigned long long int? blackzone Programming 9 03-04-2008 12:41 PM
How to print unsigned long int alaios Programming 6 07-14-2005 10:27 AM
print unsigned int alaios Programming 4 06-03-2005 09:34 AM
convert unsigned char * to unsigned long int linux_lover2005 Programming 3 04-26-2005 11:38 PM
64 bit CPU unsigned long int GodSendDeath Programming 8 03-29-2005 01:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration