I am very confused as to why this is happening, and cannot find any information on the correction of the issue.

I am doing a homework assignment in which I need to implement the RSA Algorithm and encrypt, then decrypt a plain text file which reads "Every good boy deserves food." without the quotes. I have managed to create both the public keys and the private key without difficulty, but when working on encrypting the file, which I am reading character by character with putc, I cannot get it to properly do this formula:

for encryption: C = m^e mod n

for decryption: M = C^d mod n

I have written these function which using the pow function to raise the inputed character to the power of e, and then mods it by n. The problem occurs at raising the value to the power of e.

The character y will be my example, but this is standard for all characters in the file to date.

When the character y is read into the function and sent through pow(input,e) (input is an int and e is an unsigned int, though pow calls for doubles) it returns the value of 167620825 instead of 25937424601.

e is 5, n is 91 and y is 121 in this equation.

When the final mod is done, instead of being 88, I get 8, which is ofcourse throwing the entire algorithm off balance.

Each and every character is the wrong when computed, and I am at a point of utter frustration. I am including the code below to show you the encryptMessage function to see if anyone can explain why this is not working and what I can do to get aimed in the right direction. Thank you.

Thank you,Code:void encryptMessage(int input) { unsigned int cypher = 0, //cypher key e = 0, //first public encryption key n = P*Q, //second public encryption key power = 0; //value of inputed character raised to the e e = getPublicKey(P,Q); //generate public keys //computer cypher key printf("\nEncrypt Character: %u\n", input); power = pow(((double)input),e); printf("\nEncrypt Power: %u\n", power); cypher = power%n; printf("\nEncrypt Cypher: %u\n", cypher); //fprintf(encrypt, "%c", (char)cypher); putc(cypher, encrypt); } //end encrypt method

CK