954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

RSA Encryption in C help!

So I'm trying to write this program in C that will take a message the user types in and encrypt it using an RSA public key that the user supplies. I know there are encryption functions and libraries in C but I want to actually recreate the algorithm in code to make this work. When I try to run the program, you can type in the message and the key but it just returns a value of 1 or 0 for the encrypted message. Here is my code, hope somebody can give me some advice! By the way I am using Xcode on a Mac.

/*rsa encryptor*/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

char pubkey1[20];
char pubkey2[20];
char string[20];
char ctext[20];
int pubkey1i;
int pubkey2i;
int stringi;
int keyi;
int ctexti;

int main()
{
	encryption();
	return 0;
}

int encryption()
{
	printf("Please enter your message to encrypt.\n\n");
	scanf("%s\n",string);
	stringi=atoi(string);
	printf("Now enter the first part of the public key of the person to whom the message is intended for.\n\n");
	scanf("%s\n",pubkey1);
	pubkey1i=atoi(pubkey1);
	printf("Now enter the second part of the public key of the person to whom the message is intended for.\n\n");
	scanf("%s\n",pubkey2);
	pubkey2i=atoi(pubkey2);
	math();
	return 0;
}
int math()
{
	long double key;
	
	key=pow(stringi,pubkey2i);
	keyi=key;
	ctexti=(keyi % pubkey1i);
	printf("Encrypted text:\n\n %d \n",keyi);
	
	return 0;
}
musicman432
Newbie Poster
1 post since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: