ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Welcome to LinuxQuestions.org, a friendly and active Linux Community.

You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!

Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.

If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.

Having a problem logging in? Please visit this page to clear all LQ-related cookies.

Introduction to Linux - A Hands on Guide

This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.

Click Here to receive this Complete Guide absolutely free.

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 <stdio.h>
#include <stdlib.h>
#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...

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.

LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.