Click here to Skip to main content
15,889,651 members
Home / Discussions / Algorithms
   

Algorithms

 
QuestionImpossible Numbers Pin
ricecake8-Sep-06 4:13
ricecake8-Sep-06 4:13 
AnswerRe: Impossible Numbers Pin
Kacee Giger8-Sep-06 13:13
Kacee Giger8-Sep-06 13:13 
GeneralRe: Impossible Numbers Pin
ricecake8-Sep-06 13:24
ricecake8-Sep-06 13:24 
Questionnth root? Pin
Steve Echols5-Sep-06 19:21
Steve Echols5-Sep-06 19:21 
AnswerRe: nth root? Pin
ejuanpp5-Sep-06 23:07
ejuanpp5-Sep-06 23:07 
GeneralRe: nth root? Pin
Steve Echols6-Sep-06 4:44
Steve Echols6-Sep-06 4:44 
AnswerRe: nth root? Pin
Sauruxum23-Jun-10 2:43
Sauruxum23-Jun-10 2:43 
QuestionCrypto Formula Malfunction Pin
rawstar5-Sep-06 6:34
rawstar5-Sep-06 6:34 
Hi, probably a better place for this, hopefully someone can help.

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:

<br />
<br />
//		g++ main.c -o main<br />
<br />
#include <stdio.h><br />
#include <stdlib.h><br />
#include "math.h"<br />
<br />
<br />
int do_crypto(int M, int e, int N);<br />
<br />
int main()<br />
{<br />
	<br />
	printf("...\n");<br />
	<br />
	//	TWO PRIMES FOR OUR KEY<br />
	int p = 17;<br />
	int q = 11;<br />
	//	THIRD PART OF OUR KEY (PUBLIC)<br />
	int e = 7;<br />
	//	CALCULATE THE OTHER PART OF THE PUBLIC KEY<br />
	int N = p * q;	//	= 187<br />
	<br />
	//	THE CHARACTER TO ENCODE AS ASCII<br />
	int M = 88;<br />
	//int M = "M";<br />
	<br />
	//	ENCRYPT A CHARACTER<br />
	//int C = int ( M * exp(e) ) % N;<br />
	int C = do_crypto(M, e, N);		//	int M, int e, int N)<br />
	printf("C = %d \n", C);<br />
	<br />
	<br />
	//	CALCULATE THE DECRYPT KEY<br />
	//int d = ( 1 % ( (p-1) * (q-1) ) ) / e;<br />
	int d =  ( ( (p-1) * (q-1) ) / e );<br />
	printf("d = %d \n", d);<br />
	<br />
	<br />
	// DECRYPT THE CHARACTER<br />
	int m = do_crypto(11, 23, 187);		//	int C, int d, int N)<br />
	printf("m = %d \n", m);<br />
	<br />
	<br />
	return 0;<br />
}<br />
<br />
int do_crypto(int M, int e, int N)<br />
{<br />
	int iret = int ( M * exp(e) ) % N;<br />
	<br />
	return iret;<br />
}<br />
<br />


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...
AnswerRe: Crypto Formula Malfunction Pin
Paul Conrad14-Jul-07 10:21
professionalPaul Conrad14-Jul-07 10:21 
QuestionMAP Pin
MHASSANF4-Sep-06 22:36
MHASSANF4-Sep-06 22:36 
Questionwhat are the codes of this Pin
robeelyn2-Sep-06 5:18
robeelyn2-Sep-06 5:18 
AnswerRe: what are the codes of this Pin
Ed.Poore2-Sep-06 9:39
Ed.Poore2-Sep-06 9:39 
GeneralRe: what are the codes of this Pin
Paul Conrad2-Sep-06 12:22
professionalPaul Conrad2-Sep-06 12:22 
GeneralRe: what are the codes of this Pin
Ed.Poore2-Sep-06 13:16
Ed.Poore2-Sep-06 13:16 
GeneralRe: what are the codes of this Pin
Paul Conrad3-Sep-06 5:54
professionalPaul Conrad3-Sep-06 5:54 
AnswerRe: what are the codes of this Pin
toxcct4-Sep-06 6:28
toxcct4-Sep-06 6:28 
QuestionWavelet code request Pin
Loay Al Lusi2-Sep-06 4:03
Loay Al Lusi2-Sep-06 4:03 
AnswerRe: Wavelet code request Pin
Ed.Poore2-Sep-06 9:40
Ed.Poore2-Sep-06 9:40 
GeneralRe: Wavelet code request Pin
Loay Al Lusi2-Sep-06 9:43
Loay Al Lusi2-Sep-06 9:43 
GeneralRe: Wavelet code request Pin
Ed.Poore2-Sep-06 13:13
Ed.Poore2-Sep-06 13:13 
GeneralRe: Wavelet code request Pin
Loay Al Lusi2-Sep-06 14:03
Loay Al Lusi2-Sep-06 14:03 
GeneralRe: Wavelet code request Pin
Ed.Poore2-Sep-06 21:49
Ed.Poore2-Sep-06 21:49 
GeneralRe: Wavelet code request Pin
Loay Al Lusi3-Sep-06 1:53
Loay Al Lusi3-Sep-06 1:53 
GeneralRe: Wavelet code request Pin
Paul Conrad3-Sep-06 5:28
professionalPaul Conrad3-Sep-06 5:28 
GeneralRe: Wavelet code request Pin
Ed.Poore3-Sep-06 6:06
Ed.Poore3-Sep-06 6:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.