# How do I decrypt message with RSA algorithm with modulus n = 302446877 and encryption key e 677?

Message: 196512625 25825210 250970710 140420423 22130212 288711674 26343056

Plaintext is grouped in blocks of 4 letters.

What I have so far =(

Fold[#1 n + #2 &, 0, %];
IntegerDigits[%, 4];
FromCharacterCode[%]

• What does Plaintext is grouped in blocks of 4 letters. mean precisely? I have decrypted your string but I have no idea how it's encoded because you haven't properly specified it (e.g ASCII? Numbers 1-26? Base-8, Base-256 etc.) – flinty Oct 27 '20 at 10:30

This is how to decrypt your message, however I need to know more how to decode the final numbers until I can produce a string, as mentioned in the comments:

n = 302446877;
publicExponent = 677;
{p, q} = FactorInteger[n][[All, 1]];

(* this is the same as EulerPhi[n] *)
phi = (p - 1) (q - 1);

privateExponent = PowerMod[publicExponent, -1, phi];

decryptInteger[c_, d_, n_] := PowerMod[c, d, n]

message = {196512625 , 25825210 , 250970710 , 140420423 , 22130212 ,
288711674 , 26343056};
decr = decryptInteger[#, privateExponent, n] & /@ message

(* result: {10040415, 2001112, 130303, 14132012, 1041719, 7041417, 236259039} *)


Update: based on @WReach's observation, there is a slight problem with your final number, but essentialy the message is "keep calm and do number theory!"

indices = FromDigits[#, 10] & /@
Partition[Flatten[IntegerDigits[#, 10, 8] & /@ decr], 2];
StringJoin @@ (indices /. Thread[Range[0, 99] -> CharacterRange[97, 97+99]])

(* result: "keepcalmanddonumbertheorz»" *)

• The digit pair 00 is a, 01 is b, etc. So the digit pairs 10 04 04 15 are read as keep. keepcalmanddonumbertheor.... The last group appears malformed as it contains four pairs plus a surplus digit. I believe your decryption logic is correct, so either the padding scheme eludes me or there is a transcription error in the message or a mistake was made during encryption. – WReach Oct 27 '20 at 15:20
• Thank you very much for the explanation. – suffering undergrad Nov 1 '20 at 4:27
• @sufferingundergrad please accept the answer if you feel it solved the problem, otherwise please let me know if you have any other requirements. – flinty Nov 1 '20 at 15:36