# RSA encryption input range - plaintexts that map to ciphertexts?

According to the wiki article on the RSA encryption function, the valid range of input $m$ is $0 \leq m \lt n$. However I have found that the following values of $m$ always return themselves when encrypted:

• $0$
• $1$
• $n - 1$
• $n - 2$

Have I implemented the algorithm incorrectly or am I misreading the wiki article?

-

## 1 Answer

Yes, this is textbook RSA, so by definition:

$0^e \equiv 0 \pmod{n}$

$1^e \equiv 1 \pmod{n}$

$(n - 1)^e \equiv (-1)^e \equiv -1 \equiv n - 1 \pmod{n}$

(since $e$ must be odd as $\varphi{(n)}$ is even and thus $2$ has no modular inverse modulo $\varphi{(n)}$)

This is (obviously) bad since an observer can immediately deduce the plaintext for those messages even without knowing the decryption exponent, but normally you use padding in real life RSA which makes those kind of inputs essentially impossible.

However you are wrong for $n - 2$. It does not necessarily encrypt to itself. How did you get that? You must be making some mistake in your implementation, or perhaps got lucky with a few small inputs.

Counterexample, $n = 377$, $e = 17$ ($d = 257$, $\varphi{(377)} = 336$):

$(n - 2)^e \equiv 375^{17} \equiv 124 \pmod{377}$

Are you sure you are calculating $e$ right?

-

Indeed. And that's why RSA is used with padding, to ensure that values like that cannot occur, and to ensure that the same message will have different encryptions at different times (which is another desirable property: the ciphertext leaks as little information as possible). – Henno Brandsma Oct 7 '12 at 14:46
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 21, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": false, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9288389682769775, "perplexity_flag": "middle"}