# Convert numeric message from RSA ciphertext to alphabetic

I have a set of numeric values that are supposed to represent a message encoded via textbook RSA. For example:

60889
37946
13359
61629
35960
13747


I've decrypted these values to find the corresponding messages:

1535
3109
2789
1191
2700
1829


Now I need to convert these values the alphabetic using the rule that each value represents a triplet of alphabetic characters as follows:

DOG -> 3*(262) + 14*26 + 6 = 2398
CAT -> 2*(262) + 0*26 + 19 = 1371
ZZZ -> 25*(262) + 25*26 + 25 = 17575


I'm not sure how to find the alphabetic characters once I have the original numeric message. The only way I could think to do it would be to calculate every possible triplet combination of letters then find the numeric match for each element. But this method seems way overly complicated.

Anyone have a better way to figure this out? I'm writing this all in Java, so a code example would be even better!

• The actual formula is $a\cdot 26^2+b\cdot26+c$ ($26^2$, not $262$). If there were instead 10 letters and you had to turn $a\cdot 10^2+b\cdot 10+c$ into $(a,b,c)$, how would you go about it? Feb 21, 2015 at 2:55
• Hint: when you have an integer in range [000..999] on a computer, how do you break it into 3 integers having the value of each decimal digit? Do the same with base 26 instead of base 10. $\;$ BTW, RSA is not used in that way.
– fgrieu
Feb 21, 2015 at 18:38