Thread: error with fmod() function

  1. #1
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002

    error with fmod() function

    This is the function I am using to decrypt a value using the RSA method. I seem to be having a problem with the fmod() function.

    I have followed the function through with a debugger and get the following results:

    The values of the variables are:

    C = 33
    PrivKey = 29
    ModKey = 91
    Power = pow (C, PrivKey) = 1.088690056823e+044
    M = fmod (Power, ModKey) = 87

    I have performed the calculations on Windows calculator and get the same result for the power operation but get a value of 24 after the Mod operation. This is the correct value (the initial value before encryption). There is obviously an error occurring with the fmod() function but I dont see what it is. M, Power and ModKey are all doubles so there shouldnt be a problem there. Anyone know why I am getting this error? Thanks.

    My function:

    void CipherDecrypt::DecryptData (double input)
    	C = input;
    	cout << "Decrypt" << endl << "C: " << C << endl;
    	Power = pow (C, PrivKey);
    	cout << "Power: " << Power << endl;
    	M = fmod (Power, ModKey);
    	cout << "M: " << M << endl;

  2. #2
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    I believe it's coming from a lack of precision capability from the floats. Floats can only handle so many digits with precision and you are doing operations on a seemingly inaccurate result. In other words, you need a differnet type, one that can hold larger numbers consider the following library:

    also as a side note, FLINT was sepcifically designed for cryptographic purposes, RSA, Rijndael etc. So even if you have a larger int library FLINT is always good for the encryption
    Last edited by Lynux-Penguin; 08-29-2003 at 06:08 PM.
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  3. #3
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  4. #4
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Thanks. Thought it would be a problem with the data types, wanted a second opinion though.

    Cheers for the info and the links.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM