# Help with Numbers - Newbie Problem

• 10-30-2009
Sn1per
Help with Numbers - Newbie Problem
Hiya,

I have been trying to learn C, and so far thanks to this site I have made progress. Now I want to do this, but I have been on it for hours and I have googled it and so forth but I dont know where to go.

What I am trying to do here is I have the values that I want, but I want to work it out in C. I would be ever so grateful if you could guide me.

Code:

```#include<stdio.h> #include<limits.h> int main(void) {     unsigned long long c,n,d,t;     c = 1340663;     d = 1073;     n = 2059;     // t = c^d mod n         t = c*d%n;     printf("%d", t);     printf("\n t should be 31087, if not, its wrong"); return(0); }```
Code:

```/* p = 29 q = 71 n = 2059 e = 137 d = 1073 text = yo converted to numbers = 31093 encrypted the numbers = 1340663 */```
• 10-30-2009
Obelisk
are you trying to check wether the t value is a specific value if you are then i would suggest putting it in a if loop.
• 10-30-2009
slingerland3g
I have not checked out the limits range MAX, but I think you are beyond that. Also c*d is not the same as c^d. Are you really after doing a bitwise 'exclusive or' operation instead?
• 10-30-2009
bithub
Why do you think the answer should be 31087? Do the math on a calculator first; I'm willing to bet that gives you a different answer. I'll give you a hint: The result of x%y can never be bigger than y. Your math is wrong.
• 10-30-2009
Sn1per
Thanks for the response so far SlingerLand3g & Obelisk.

Basically the equation:
Code:

`// t = c^d mod n`
Is the equation to decrypt RSA encryption.

C is my Ciphertext/digits
D is the Public Key
N is the Private Key

The string that I have encrypted is simply "yu"
When converted to digits the value is "31087"
And the Encrypted value of the converted digits is "75603"

So, I know what the value of "t" shoud be which is "75603", but I want the program to work that out for me. From there I am planning to make it more complicated, but I have came to this stop whereby I cannot proceed any further because I am out of Limit Range.

Any advice on how to go on about this would be appreciate and sorry if my question wasn't very clear at the start.
• 10-30-2009
Sn1per
Quote:

Originally Posted by bithub
Why do you think the answer should be 31087? Do the math on a calculator first; I'm willing to bet that gives you a different answer. I'll give you a hint: The result of x%y can never be bigger than y. Your math is wrong.

Thank you, you might be right and I have my numbers wrong, but I was wondering how could I get extremly large numbers for such calculations? what would be the best way to go on about it? even unsigned long long int is not good enough.
• 10-30-2009
slingerland3g
If quzah pipes in...I know he wrote something on the boards concerning simple encryption and it dealt with bitwise operators as I believe you are needing here.

http://www.cprogramming.com/tutorial/xor.html
• 10-30-2009
laserlight
Quote:

Originally Posted by Sn1per
you might be right and I have my numbers wrong, but I was wondering how could I get extremly large numbers for such calculations? what would be the best way to go on about it? even unsigned long long int is not good enough.

You could use a bignum library like GMP, though in this case it should be possible to take advantage of modulo arithmetic.
• 10-30-2009
Sn1per
Quote:

Originally Posted by slingerland3g
If quzah pipes in...I know he wrote something on the boards concerning simple encryption and it dealt with bitwise operators as I believe you are needing here.
Cprogramming.com - Articles - XOR Encryption

Thanks SlingerLand3g, I read that tutorial earlier, believe me I have been reading page after page all day today but no solution.

I like the other methods of encryption as well, but I am really interested in decrypting RSA. But first, I have to be able to figure out how to decrypt the value of something that I already know while I have the equation.
• 10-30-2009
Sn1per
Quote:

Originally Posted by laserlight
You could use a bignum library like GMP, though in this case it should be possible to take advantage of modulo arithmetic.

Thanks for the help, I appreciate it. Though I was hoping to learn away to do it myself rather than rely on a library.

But if anyone has any other suggestions on how to do it via a prticular iteration or something, then I would love to learn how it is done or read more about it.