Share your knowledge at the LQ Wiki.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org Crypto Formula
 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

 09-05-2006, 11:45 AM #1 rubadub Member   Registered: Jun 2004 Posts: 236 Rep: Crypto Formula Hi, For one of my programs i'm trying to impliment my own version of the RSA algorithm, the encryption works fine, however the decrption does not, even though it uses basically the same algorithm. The code is as follows: Code: ```// g++ main.c -o main #include #include #include "math.h" int do_crypto(int M, int e, int N); int main() { printf("...\n"); // TWO PRIMES FOR OUR KEY int p = 17; int q = 11; // THIRD PART OF OUR KEY (PUBLIC) int e = 7; // CALCULATE THE OTHER PART OF THE PUBLIC KEY int N = p * q; // = 187 // THE CHARACTER TO ENCODE AS ASCII int M = 88; //int M = "M"; // ENCRYPT A CHARACTER //int C = int ( M * exp(e) ) % N; int C = do_crypto(M, e, N); // int M, int e, int N) printf("C = %d \n", C); // CALCULATE THE DECRYPT KEY //int d = ( 1 % ( (p-1) * (q-1) ) ) / e; int d = ( ( (p-1) * (q-1) ) / e ); printf("d = %d \n", d); // DECRYPT THE CHARACTER int m = do_crypto(11, 23, 187); // int C, int d, int N) printf("m = %d \n", m); return 0; } int do_crypto(int M, int e, int N) { int iret = int ( M * exp(e) ) % N; return iret; }``` When decrypting I have put in actual values for the keys etc, and the result should be 88. The actual formulas are: ENCRYPT: C = Me (Mod N) DECRYPT: M = Cd (Mod N) *** Please note the 'e' and 'd' are supposed to be superscript, e.g. raised to the power of...
09-06-2006, 04:39 AM   #2
magnus.therning
LQ Newbie

Registered: Jul 2006
Location: Gothenburg
Posts: 21

Rep:
Quote:
 Originally Posted by rubadub Hi, For one of my programs i'm trying to impliment my own version of the RSA algorithm, the encryption works fine, however the decrption does not, even though it uses basically the same algorithm. The code is as follows: Code: ```int do_crypto(int M, int e, int N) { int iret = int ( M * exp(e) ) % N; return iret; }``` When decrypting I have put in actual values for the keys etc, and the result should be 88. The actual formulas are: ENCRYPT: C = Me (Mod N) DECRYPT: M = Cd (Mod N) *** Please note the 'e' and 'd' are supposed to be superscript, e.g. raised to the power of...
exp(double) is the base-e exponential function, i.e. it calculates (roughly) 2.71^e. That's hardly what you are looking for.

You should probably also factor in the severe risk for integer overflow when using builtin types. Your goal is to make a program that calculates 88^7, which is 40867559636992. A 32-bit machine can't represent that in an int.

 09-06-2006, 10:16 AM #3 juvestar15 Member   Registered: Aug 2005 Location: Australia Distribution: Debian Sid Posts: 60 Rep: What magnus said. ^^ Not sure on the data type but the formula should be this.... if I can remember crypto class. iret = pow(M,e) % N;

 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 Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post milad126 Linux - General 3 09-06-2006 06:49 AM debiant Programming 10 08-31-2006 08:28 PM Four Linux - Newbie 1 03-30-2006 09:46 PM Bigun Linux - Software 2 08-16-2004 03:07 PM hellblade Linux - Software 2 04-29-2004 11:23 AM

LinuxQuestions.org

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

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -