LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   int value larger then unsigned long (https://www.linuxquestions.org/questions/programming-9/int-value-larger-then-unsigned-long-156828/)

jpc82 03-12-2004 02:39 PM

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?

andzerger 03-12-2004 02:51 PM

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

jim mcnamara 03-12-2004 03:29 PM

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.

jpc82 03-12-2004 03:54 PM

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.


All times are GMT -5. The time now is 08:01 AM.