# Message input format for RSA algorithm

I was trying to implement the RSA algorithm myself. I have written the key generation part. My question is if I have the word "apple" which I want to encrypt, do I have to convert each alphabet to ASCII and then apply RSA to each letter or are there some other way?

• Welcome to crypto.SE. You are asking how to format plaintext in (I guess) textbook RSA. That's not standardized, especially when using toy moduli (less than a hundred decimal digits) as in some introductory courses.Practices vary, see what the course does. For very small parameters, many use the method in section VIII of the original RSA paper, or some simpler variant. This question has answers about more standard ways. – fgrieu Mar 4 at 13:32
• Similar Q/A answered by me. Dang, I'll have to merge possibly. – Maarten Bodewes Mar 4 at 14:05

It would make sense to encrypt as many bytes as possible at the same time. For example, a word like apple can be written as this sequence of byte values in hexadecimal 61 70 70 6c 65. You can treat this as a 40-bit number 0x6170706c65, which is equal to 418498243685. When this number is retrieved after decrypting the ciphertext, just convert it back into hexadecimal to get the original byte values.
Obviously you would need an RSA modulus of at least 40 bits to encrypt a word of this length. In practice, it would have to be a lot longer than that. An important part of RSA encryption is the use of randomized padding. Without it, the word apple would always be encrypted to the same value, so an attacker could easily encrypt every word in the dictionary and compare the results with your ciphertext to find out what word you had encrypted.