๐Ÿ” RSA Prime Number Generation Process

๐Ÿ” Step 1: Sieve of Eratosthenes

Find Small Primes up to โˆšn

Prime Numbers
Composite Numbers

Sieve Algorithm Steps

  • Create list of consecutive integers 2 to n
  • Start with smallest prime p = 2
  • Mark multiples of p (except p itself)
  • Repeat until pยฒ > n

๐Ÿงช Step 2: Miller-Rabin Primality Test

Candidate

982451653
Bit Length: 30
Round 1
Base: 7
โœ“ PASS
Base 7 Test
n-1 = 982451652
2^r ร— d = 2^2 ร— 245612913
x = 7^d mod n = 245612913
Result: Probable Prime
Round 2
Base: 11
โœ“ PASS
Base 11 Test
x = 11^d mod n = 245612913
xยฒ mod n = 245612913
Result: Probable Prime
Round 3
Base: 13
โœ“ PASS
Base 13 Test
x = 13^d mod n = 245612913
xยฒ mod n = 245612913
Result: Probable Prime

PROBABLE

PRIME โœ“
Confidence: 99.998%
If composite found, repeat with new candidate

Miller-Rabin Test Details

1. Express n-1 as 2^r ร— d where d is odd

2. For each witness base a:

3. Compute x = a^d mod n

4. If x = 1 or x = n-1, continue to next witness

5. For j = 1 to r-1:

a. x = xยฒ mod n

b. If x = n-1, continue to next witness

c. If x = 1, declare composite

6. Declare composite if no early exit

Miller-Rabin Algorithm

  • Write n-1 = 2^r ร— d (where d is odd)
  • Choose random base a: 2 โ‰ค a โ‰ค n-2
  • Compute x = a^d mod n
  • If x = 1 or x = n-1, n passes this round
  • For j = 1 to r-1, compute x = xยฒ mod n
  • If x = n-1 at any point, n passes this round
  • Otherwise, n is composite
  • Error probability: 1/4^k = 1/64 for k=3

Test Visualization

Step 1: Find d, r
n-1 = 2^r ร— d
982451652 = 2^2 ร— 245612913
Step 2: Compute x
x = a^d mod n
7^245612913 mod 982451653
Step 3: Check x
x = 1 or x = n-1?
x = 245612913 (continue)
Step 4: Square x
x = xยฒ mod n
x = 245612913ยฒ mod 982451653

๐Ÿ”‘ Step 3: RSA Key Generation

Prime p

1024 bits
First large prime number
ร—

Prime q

1024 bits
Second large prime number
=

RSA Modulus n

2048 bits
Public key component
๐Ÿ”’ Factoring n into pร—q must be computationally infeasible

Key Sizes & Security Levels

1024-bit: Deprecated
2048-bit: Current
3072-bit: Future
4096-bit: High