English|Español·Free Tools
All free tools

RSA Algorithm Calculator – Step-by-Step Key Generation

Calculate an educational RSA public key and private key from two prime numbers. See n, φ(n), e, d, modular inverse, encryption, and decryption step by step.

Use this RSA algorithm calculator to study RSA key generation step by step. Enter two different prime numbers, select the public exponent automatically or manually, and calculate the modulus, Euler totient, public key, private key, and optional numeric encryption example.

What Is the RSA Algorithm?

RSA is a public-key cryptosystem built around modular arithmetic and the difficulty of factoring a large number formed from two secret primes. Its public and private values are mathematically related, allowing operations performed with one key to be reversed with the corresponding key under the RSA construction.

Step 1: Choose Two Prime Numbers

Choose two different primes named p and q. This educational calculator verifies that both inputs are whole prime numbers and rejects equal values. Real RSA systems generate much larger secret primes with cryptographically secure software.

Step 2: Calculate the Modulus n

Multiply the primes to obtain n = p × q. The modulus n is included in both the public and private key pairs. For p = 61 and q = 53, n = 61 × 53 = 3233.

Step 3: Calculate Euler’s Totient φ(n)

When p and q are distinct primes, Euler’s totient is φ(n) = (p − 1)(q − 1). For p = 61 and q = 53, φ(n) = 60 × 52 = 3120.

Step 4: Select the Public Exponent e

The educational rule used here requires 1 < e < φ(n) and gcd(e, φ(n)) = 1. In automatic mode, the calculator prefers 65537 when valid for the selected values, then tries smaller classroom-friendly exponents such as 17.

Step 5: Calculate the Private Exponent d

The private exponent d is the modular inverse of e modulo φ(n). This means e × d ≡ 1 mod φ(n). The calculator uses the extended Euclidean algorithm to find that inverse.

RSA Public Key and Private Key

This demonstration writes the public key as (e, n) and the private key as (d, n). The public key may be shared, but d and the original primes must remain secret in a real implementation.

RSA Encryption Formula

For a numeric message m satisfying 0 ≤ m < n, textbook RSA encryption calculates c = m^e mod n. The result c is the encrypted integer.

RSA Decryption Formula

Textbook RSA decryption calculates m = c^d mod n. The calculator substitutes the selected values into both modular-power equations so students can follow the complete round trip.

Automatic and Manual Exponent Modes

Automatic mode selects a valid e for you. Manual mode is useful when a textbook, examination, assignment, or classroom example specifies a particular public exponent.

Why the Message Must Be Smaller Than n

The RSA mathematical operation works with integers modulo n. Therefore, the numeric message representative must be between 0 and n − 1. Real applications encode and pad data before applying RSA instead of encrypting an arbitrary text message directly.

Textbook RSA Is Not Secure Encryption

This calculator demonstrates raw modular exponentiation with small primes and no padding. Textbook RSA is deterministic and lacks the protections required for real data. Production encryption uses reviewed cryptographic libraries, appropriately sized keys, and a standardized scheme such as RSAES-OAEP.

Designed for RSA Learning and Practice

The calculator is intended for computer science students, engineering students, teachers, discrete mathematics exercises, cybersecurity lessons, examinations, and anyone learning RSA calculations with p, q, n, φ(n), e, and d.

How Is the Result Calculated?

n = p × q; φ(n) = (p − 1)(q − 1); gcd(e, φ(n)) = 1; d = e⁻¹ mod φ(n); c = m^e mod n; m = c^d mod n

RSA Algorithm Example with p = 61 and q = 53

Let p = 61 and q = 53. Then n = 61 × 53 = 3233 and φ(n) = 60 × 52 = 3120. Choose e = 17 because gcd(17, 3120) = 1. The modular inverse is d = 2753 because (17 × 2753) mod 3120 = 1. The public key is (17, 3233), and the educational private key is (2753, 3233).

Frequently Asked Questions

What does an RSA algorithm calculator do?

It calculates the main values in an educational RSA example: p, q, n, φ(n), e, d, the public key, the private key, and optional numeric encryption and decryption.

What inputs are required for RSA key generation?

Enter two different whole prime numbers p and q. You may let the calculator select e automatically or enter a valid custom exponent.

Why must p and q be prime?

The classic RSA construction uses distinct primes so n = pq and φ(n) can be calculated as (p − 1)(q − 1), providing the modular structure needed to derive the exponents.

Can p and q be the same prime?

No. This calculator requires two different primes, as standard educational RSA key generation does.

How is n calculated in RSA?

Multiply the two primes: n = p × q. The value n is the modulus used in the public and private operations.

How is φ(n) calculated?

For two distinct primes p and q, φ(n) = (p − 1)(q − 1).

How is the public exponent e selected?

This calculator requires e to be greater than 1, smaller than φ(n), and coprime with φ(n). Automatic mode tests common valid values before searching for another odd candidate.

Why is 65537 commonly used as e?

65537 is a widely used public exponent that offers practical efficiency and avoids several problems associated with poorly chosen very small exponents. It must still be valid for the selected RSA parameters.

What does coprime mean?

Two integers are coprime when their greatest common divisor is 1. RSA requires gcd(e, φ(n)) = 1 so that e has a modular inverse.

How is the private exponent d calculated?

d is the modular inverse of e modulo φ(n). It satisfies e × d ≡ 1 mod φ(n) and can be found with the extended Euclidean algorithm.

What is the RSA public key?

In this educational representation, the public key is the pair (e, n).

What is the RSA private key?

This calculator displays the educational pair (d, n). Real implementations also protect additional private parameters and often use optimized representations.

How does RSA encryption work in this calculator?

For a numeric message m between 0 and n − 1, it calculates the ciphertext c = m^e mod n.

How does RSA decryption work?

It recovers the numeric message by calculating m = c^d mod n.

Can I encrypt text with this calculator?

No. The optional input accepts one numeric message representative. It does not encode text, split data into blocks, or apply secure padding.

Is this RSA calculator safe for real encryption?

No. It uses small user-selected primes and textbook RSA without secure padding. It is intended only for education and mathematical demonstrations.

What is RSA-OAEP?

RSAES-OAEP is a standardized RSA encryption scheme that adds randomized encoding and security protections absent from textbook RSA. It should be implemented through a trusted cryptographic library, not recreated from this demonstration.

What RSA key size is used in real systems?

Current NIST transition guidance accepts RSA key-transport moduli of at least 2048 bits. This calculator’s small inputs are intentionally far below production key sizes.

Does this calculator generate secure random primes?

No. You enter small primes manually so every mathematical step remains visible and suitable for classroom exercises.

Is the RSA algorithm calculator free?

Yes. It is free to use and does not require an account.