0
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – fgrieu Mar 4 at 13:32
  • 2
    $\begingroup$ Similar Q/A answered by me. Dang, I'll have to merge possibly. $\endgroup$ – Maarten Bodewes Mar 4 at 14:05
0
$\begingroup$

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.

Standard padding schemes like OAEP recommend the use of at least 64 random bits to ensure that the likelihood of the same word being encrypted the same way is negligibly small. You also need to ensure that your modulus can't easily be factored, which means it should be a number of at least 1024 bits.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.