Help with Numbers - Newbie Problem

This is a discussion on Help with Numbers - Newbie Problem within the C Programming forums, part of the General Programming Boards category; Hiya, I have been trying to learn C, and so far thanks to this site I have made progress. Now ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    10

    Question 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
    */
    Thanks for your help in advance.
    Last edited by Sn1per; 10-30-2009 at 01:18 PM. Reason: brought in new values

  2. #2
    Registered User
    Join Date
    Sep 2009
    Location
    USA
    Posts
    63
    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.

  3. #3
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    602
    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?

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    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.
    bit∙hub [bit-huhb] n. A source and destination for information.

  5. #5
    Registered User
    Join Date
    Oct 2009
    Posts
    10
    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.

  6. #6
    Registered User
    Join Date
    Oct 2009
    Posts
    10
    Quote Originally Posted by bithub View Post
    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.

  7. #7
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    602
    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
    Last edited by slingerland3g; 10-30-2009 at 01:09 PM.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,588
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Oct 2009
    Posts
    10
    Quote Originally Posted by slingerland3g View Post
    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. #10
    Registered User
    Join Date
    Oct 2009
    Posts
    10
    Quote Originally Posted by laserlight View Post
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with adding up numbers from a txt file
    By Leo12 in forum C Programming
    Replies: 1
    Last Post: 02-18-2009, 12:50 PM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. Problem with random numbers
    By yaya in forum C++ Programming
    Replies: 6
    Last Post: 05-30-2007, 10:30 AM
  4. Newbie question: Problem with malloc
    By Ikim in forum C Programming
    Replies: 2
    Last Post: 02-05-2006, 09:11 PM
  5. Random Numbers...Problem With FAQ Answer
    By sitestem in forum C++ Programming
    Replies: 12
    Last Post: 04-14-2004, 09:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21