Duration: 90 Minutes
Prerequisites: Basic understanding of prime numbers and algebra.
Objective: Students will understand the mathematical foundation of RSA (GCD and Modular Arithmetic) and observe how these concepts are implemented in code.
- Concept: Explain Modular Arithmetic (Clock Math). Focus on why it’s useful for cryptography: it’s easy to perform but hard to "undo" without specific information.
-
Exercise: Simple Modular exponentiation.
-
Question: What is
$7^3 \pmod{10}$ ? -
Work:
$7 \times 7 = 49 \equiv 9$ .$9 \times 7 = 63 \equiv 3$ .
-
Question: What is
-
Online Tool: WolframAlpha (Type:
7^3 mod 10) or the Omni Calculator - Modulo.
[Image of Euclidean Algorithm flowchart]
- The Problem: For RSA, we need to find two numbers that are "coprime" (GCD = 1).
-
The Algorithm: Teach Euclidean Algorithm (repeated division).
-
Example: Find
$GCD(1071, 462)$ . $1071 = 2(462) + 147$ $462 = 3(147) + 21$ -
$147 = 7(21) + 0 \rightarrow$ GCD is 21.
-
Example: Find
-
Guided Practice: Have students find
$GCD(35, 12)$ . (Result is 1, so they are coprime—essential for RSA). - Online Tool: Calculator.net GCD Calculator.
Explain the five steps of RSA using the logic found in the GitHub repo's TestOne:
-
Pick two primes (
$p, q$ ): Keep them small for class (e.g., 61 and 53). -
Compute
$n = p \times q$ : This is the modulus used in the code. -
Compute Totient
$\phi(n) = (p-1)(q-1)$ : This is where the Euclid math comes in. -
Choose
$e$ : Must be coprime with$\phi(n)$ (use Euclid here!). -
Determine
$d$ : The "modular inverse" (the secret key).
Open the SimpleRSA GitHub and walk through the four levels of complexity provided:
-
TestOne: Highlight how it encrypts one character at a time using
MulMod(). This mirrors the math they did in step 1. -
TestTwo/Three: Discuss the
ModularPow()function. Explain that for large numbers, we can't just do$base^{exponent}$ because the number becomes too large for a computer to hold (overflow). - TestFour: Show how "packing" works (putting multiple characters into one BigInteger). This is how real-world encryption is efficient.
- Break students into pairs.
-
Student A (Receiver): Picks two small primes, calculates
$n$ and$e$ , and gives them to Student B. -
Student B (Sender): Uses a calculator to encrypt a single number (a "message") using
$m^e \pmod{n}$ . -
Student A: Decrypts it using their private key
$d$ . -
Calculator Tip: Use the Use the Google Search Bar or a Scientific Calculator (typically the
%ormodbutton).
- Code Reference: LandSharkFive/SimpleRSA
- Visualizer: RSA Visualizer
- Advanced Reading: The GitHub README suggests the Handbook of Applied Cryptography.