RSA Encryption Calculator
Example Data Table
| Scenario | p | q | e | Message | n | φ(n) | d |
|---|---|---|---|---|---|---|---|
| Teaching demo | 61 | 53 | 17 | HELLO | 3233 | 3120 | 2753 |
| Small practice set | 47 | 59 | 13 | DATA | 2773 | 2668 | 821 |
| Class exercise | 71 | 67 | 19 | MATH | 4757 | 4620 | 1459 |
Formula Used
RSA starts by selecting two primes, p and q. The modulus is n = p × q. Euler’s totient becomes φ(n) = (p − 1)(q − 1). Choose a public exponent e where gcd(e, φ(n)) = 1.
The private exponent is the modular inverse of e under φ(n), so d ≡ e⁻¹ mod φ(n). Encryption of one numeric block m uses c = m^e mod n. Decryption uses m = c^d mod n.
This page converts each character into its ASCII code, encrypts every code separately, and then decrypts each block to verify recovery. The tool uses repeated squaring for fast modular exponentiation and the extended Euclidean algorithm to solve for the private exponent.
How to Use This Calculator
- Enter two different prime numbers for p and q.
- Provide a valid public exponent e smaller than φ(n).
- Type a plaintext message. Keep character codes below the modulus.
- Optionally paste ciphertext integers to test direct decryption.
- Press Submit to display the result section above the form.
- Review generated keys, numeric blocks, ciphertext, and recovered text.
- Use the export buttons to save a CSV or PDF summary.
About This Tool
RSA is a foundational public key cryptosystem built on modular arithmetic and prime factorization. In teaching settings, it helps students connect number theory with practical data protection. This tool emphasizes transparency by showing the modulus, totient, public exponent, private exponent, block conversions, encrypted values, and decrypted outputs in one place.
The interface is intentionally simple, but the workflow is comprehensive. You can test valid or invalid parameter choices, observe why coprimality matters, and check whether a message can fit under the chosen modulus. Since characters are processed as ASCII values, the calculator is especially useful for classroom examples, quick demonstrations, and concept validation.
Real implementations use very large primes, padding schemes, secure random generation, and arbitrary precision arithmetic libraries. This educational version uses small integers for clarity and speed inside a browser-based form. It should be treated as a study aid rather than a production encryption system.
FAQs
1. Why must p and q be prime?
Prime factors make Euler’s totient predictable and allow the private key to work correctly. Composite inputs break the usual RSA assumptions and can invalidate decryption.
2. Why does e need to be coprime with φ(n)?
A modular inverse for e exists only when gcd(e, φ(n)) equals one. Without that inverse, you cannot compute a valid private exponent d.
3. Why can message characters fail validation?
Each encoded character must be smaller than the modulus n. If n is too small, some character codes cannot be encrypted as single blocks.
4. Is this tool secure for real secrets?
No. It is designed for learning and demonstration. Production RSA requires huge keys, secure padding, randomness, and big integer support.
5. What does the private exponent d represent?
It is the modular inverse of e modulo φ(n). Decryption uses d to reverse ciphertext back into the original numeric message blocks.
6. Why are ciphertext values larger than character codes?
Encryption raises each message block to a power and reduces it modulo n. That process usually produces values that look unrelated to the original text.
7. What can I export from this page?
You can export the current calculation as a CSV file or a simple PDF summary containing keys, message blocks, ciphertext values, and recovered text.