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()
	return 0;

int encryption()
	printf("Please enter your message to encrypt.\n\n");
	printf("Now enter the first part of the public key of the person to whom the message is intended for.\n\n");
	printf("Now enter the second part of the public key of the person to whom the message is intended for.\n\n");
	return 0;
int math()
	long double 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 thanks a lot!

Be a part of the DaniWeb community

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