{"id":251,"date":"2026-11-13T12:35:56","date_gmt":"2026-11-13T04:35:56","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-rsa-encrypts-with-a-public-exponent\/"},"modified":"2026-11-13T21:53:43","modified_gmt":"2026-11-13T13:53:43","slug":"how-rsa-encrypts-with-a-public-exponent","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-rsa-encrypts-with-a-public-exponent\/","title":{"rendered":"How RSA encrypts with a public exponent"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>RSA<\/strong> builds a public modulus n as a product of two secret primes and a public exponent e that is coprime to \u03bb(n), the Carmichael function of n. The private exponent d is the modular inverse of e modulo \u03bb(n). Encryption of an integer m in 0 \u2026 n\u22121 is m^e mod n. Decryption is c^d mod n, which returns m. The public operation does not reveal p, q, or d. Raw RSA is a deterministic map on integers. A confidential message uses a standard padding scheme, usually around a symmetric key.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">A sender should be able to transform a message so that only the holder of a private key can invert the transform, using parameters the sender can publish. RSA publishes n and e. Inversion uses d. Euler&#8217;s theorem, in the form m^{\u03bb(n)} \u2261 1 (mod n) when m is coprime to n, makes the exponents cancel: ed = 1 + k \u03bb(n), so m^{ed} \u2261 m (mod n). The Chinese remainder theorem extends the same identity to every residue, including those that share a factor with n.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The map m \u21a6 m^e mod n is completely determined by the public key and the integer m. The same m always produces the same ciphertext. A message longer than n does not fit in one residue. Those two facts are why a deployed encryption scheme pads and why it usually encrypts a short symmetric key rather than a long message.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">For a correctly generated key, decryption recovers every integer m in 0 \u2026 n\u22121. Key generation is two primality tests, a product, a coprimality test, and one modular inverse. Encryption and decryption are modular exponentiations, polynomial in the bit length of n. Extra secret storage is p, q, and d. Implementations often decrypt modulo p and modulo q and combine the halves with the Chinese remainder theorem. The result is the same m.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The theorem is about the integer map. It does not say that a raw residue hides equality of messages, and it does not say that an altered ciphertext fails in a useful way. Those are properties of a padding and encoding scheme built around the map. Signature generation is the private exponent applied to a hash, which is a different construction from encryption.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>Draw two distinct large random primes p and q. Set n = p q and \u03bb = lcm(p \u2212 1, q \u2212 1).<\/li>\n<li>Choose a public exponent e with gcd(e, \u03bb) = 1. The private exponent d is the inverse of e modulo \u03bb.<\/li>\n<li>Publish n and e. Keep p, q, and d secret.<\/li>\n<li>To encrypt an integer m with 0 \u2264 m &lt; n, send m^e mod n. To decrypt a ciphertext c, compute c^d mod n.<\/li>\n<li>For a real message, encode it with a standard padding scheme, or encrypt a symmetric key and encrypt the message with that key. The residue map is the same either way.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">Correctness is the exponent identity modulo n. Confidentiality of arbitrary bytes is a padding and hybrid construction around that identity. Diffie-Hellman agrees on a shared exponent without a public composite. RSA is the public-exponent residue map.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when a long message is split into raw residues<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Chop a message into blocks smaller than n and apply the public exponent to each block<\/td>\n<td>Each block is a deterministic public function of itself. Equal blocks stay equal, and the encoding is not a secure encryption scheme. Padding or hybrid encryption is the layer that carries a message.<\/td>\n<\/tr>\n<tr>\n<td>Publish d with n and e<\/td>\n<td>The inverse exponent undoes the public map. Publishing it publishes decryption.<\/td>\n<\/tr>\n<tr>\n<td>Pick e that shares a factor with \u03bb<\/td>\n<td>The inverse modulo \u03bb does not exist, so there is no decryption exponent for that e.<\/td>\n<\/tr>\n<tr>\n<td>Skip the primality test and multiply two random odd numbers<\/td>\n<td>The correctness proof used primes, so that \u03bb has the form the inverse is taken modulo. A composite factor breaks that setup.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">A shared secret from public powers is Diffie-Hellman. Modular exponentiation is the arithmetic inside both. RSA is the public map m^e mod n and the private inverse.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">This Python fragment publishes n = 61\u00d753 and e = 17, then encrypts the integer 65. Decryption with the inverse exponent modulo \u03c6(n) returns 65. It prints the ciphertext <code>2790<\/code>.<\/p>\n\n<pre><code class=\"language-python\">p, q, e, m = 61, 53, 17, 65\nn = p * q\nphi = (p - 1) * (q - 1)\nd = pow(e, -1, phi)\nc = pow(m, e, n)\nassert pow(c, d, n) == m\nprint(c)\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">*<em>RSA*<\/em> signs TLS certificates, SSH user keys, and OpenPGP messages. The public exponent encrypts a small integer or verifies a signature; a long message is encrypted with a symmetric key. OAEP is the padding around the integer encryption.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Drop raw residues as a message format. Keep the key generation and the exponent for a scheme that pads, or that wraps a symmetric key, and treat signing a hash as its own operation.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">We publish this so a search for RSA returns the public exponent, the private inverse modulo \u03bb(n), and the reason raw residues are not a message format. <strong>RSA publishes n and e, encrypts an integer as m to the e modulo n, and decrypts with the inverse exponent modulo \u03bb(n).<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Short answer: RSA builds a public modulus n as a product of two secret primes and a public exponent e that is coprime to \u03bb(n), the Carmichael function of n. The private exponent d is the modular inverse of e modulo \u03bb(n). Encryption of an integer m in 0&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,49],"tags":[],"class_list":["post-251","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-cryptography"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=251"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/251\/revisions"}],"predecessor-version":[{"id":650,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/251\/revisions\/650"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}