RSA Calculator — Key Generation, Encrypt & Decrypt
Enter two prime numbers p and q, a public exponent e, and an integer message m to see RSA key generation and encryption/decryption worked out step by step.
Encrypted message: c = m^e mod n
Compute modulus n = p × q
Compute Carmichael totient λ(n) = lcm(p−1, q−1)
Public exponent e (must be coprime to λ(n))
Private exponent d = e⁻¹ mod λ(n)
Encrypt: c = m^e mod n
Decrypt: m = c^d mod n
- 1
Modulus n = p × q
61 × 53 = 3,233 - 2
Carmichael totient λ(n) = lcm(p−1, q−1)
lcm(60, 52) = 780 - 3
Private exponent d = e⁻¹ mod λ(n)
17⁻¹ mod 780 = 413Computed via the extended Euclidean algorithm. - 4
Ciphertext c = m^e mod n
65^17 mod 3,233 = 2,790
此計算機如何運作?
RSA key generation: pick primes p, q → n = p·q, λ(n) = lcm(p−1,q−1), choose e coprime to λ(n) → d = e⁻¹ mod λ(n). Public key = (n,e), private key = (n,d). Encrypt m: c = m^e mod n. Decrypt: m = c^d mod n. All arithmetic uses fast binary exponentiation and BigInt for exactness.
公式
How this is calculated
RSA (Rivest–Shamir–Adleman, 1977) is the most widely deployed public-key cryptosystem. Security rests on the computational difficulty of factoring the product of two large primes. The key generation steps are: (1) choose two distinct primes p and q; (2) compute the modulus n = p × q; (3) compute Carmichael's totient λ(n) = lcm(p−1, q−1) — the modern standard, preferred over Euler's φ(n) = (p−1)(q−1) because it produces a smaller private exponent; (4) choose a public exponent e with 1 < e < λ(n) and gcd(e, λ(n)) = 1 — 65537 is the near-universal choice in practice because it is prime, coprime to almost all λ(n) values, and has a short binary representation that speeds modular exponentiation; (5) compute the private exponent d as the modular inverse of e modulo λ(n) via the extended Euclidean algorithm.
Encryption takes integer message m (0 ≤ m < n) and computes ciphertext c = m^e mod n using fast binary exponentiation. Decryption recovers the message as m = c^d mod n. The round-trip works because e and d are modular inverses: m^(e·d) ≡ m (mod n) by the Carmichael theorem.
This calculator uses JavaScript BigInt for exact arithmetic and is designed for educational use with small primes. Real RSA uses primes of 1024–4096 bits; this tool limits p and q to 1 000 000 to keep computation instant in the browser. A textbook RSA encrypt of a raw integer is also not semantically secure without proper padding (OAEP in production). The step-by-step panel shows every intermediate value so you can follow the algorithm by hand.
常見問題
The private key d is the modular inverse of e modulo λ(n). A modular inverse exists if and only if gcd(e, λ(n)) = 1. Without this, decryption is impossible. Common safe choices are e = 3, 17, or 65537.
65537 = 2^16 + 1 is prime, so gcd(65537, λ(n)) = 1 for almost any choice of p and q. Its binary form (10000000000000001) has only two 1-bits, making modular exponentiation with e extremely fast. It also prevents some small-exponent attacks.
No. Real RSA uses primes of 2048–4096 bits and mandatory padding schemes (OAEP). This calculator uses small primes for educational demonstration only — the keys it generates are trivially factorable and must never be used for real security.
TG we-Calculate Editorial Team. (2026). RSA Calculator — Key Generation, Encrypt & Decrypt [Online calculator]. TG we-Calculate. https://we-calculate.com/zh-tw/calculator/rsa-calculator
TG we-Calculate Editorial Team. "RSA Calculator — Key Generation, Encrypt & Decrypt." TG we-Calculate. 2026. https://we-calculate.com/zh-tw/calculator/rsa-calculator.
TG we-Calculate Editorial Team, "RSA Calculator — Key Generation, Encrypt & Decrypt," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/zh-tw/calculator/rsa-calculator
@misc{wecalculate_rsa_calculator, title = {RSA Calculator — Key Generation, Encrypt & Decrypt}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/zh-tw/calculator/rsa-calculator}}, year = {2026}, note = {TG we-Calculate} }
這個計算機對您有幫助嗎?
