# How to encrypt strings in RSA (exercise)

I'm trying to solve a crypto RSA problem from my last exam in a clean way, but I'm stuck in the last step...

First of all, we are using an alphabet with 27 characters (i.e. spanish alphabet: A-Z + Ñ). We will code each char as A=0, B=1, ..., N=13, Ñ=14, O=15, ..., Y=25, Z=26.

We have d=7, n=33, e=3.

As 271 < 33 < 272 we can split our message in blocks of 1 character each.

We want to encrypt the string NIÑO, so:

• N → 137 mod 33 = 7 → H
• I → 87 mod 33 = 2 → C
• Ñ → 147 mod 33 = 20 → T
• O → 157 mod 33 = 27 → ¿?
• This is just zero based indexing. If C = 2 then A = 0. As Ñ is 14 then 27 must be...Oh, it's a joke, it's out of range of the alphabet. In that case the outcome is undefined. Aug 22, 2022 at 23:06

## 1 Answer

You are right that the problem statement does not allow to encode the whole ciphertext as letters. Options includes writing the ciphertext as HCT27 or 7 2 20 27 or 07022027, and explain why.

Note: in standard expositions of RSA, encryption uses exponent e, not d as in the proposed solution. But with this small n it turns out that makes no difference in the result. In my view, using such a small n in RSA exercises is ill-advised from a pedagogical standpoint, especially with no reminder that for RSA to be secure, a necessary condition is that n has hundreds decimal digits.

• Ooops! You're right, my fault :-). Thanks! Aug 23, 2022 at 14:41