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;
}

Hello~may i know whther your problem was solved? i am also looking for a RSA on mac,could you please send me your source code? my email is sccdqx@gmail.com thanks a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.