12.3.2Advanced Networks and SecurityCore

RSA Primes, Key Pairs and Limits

Use a tiny modular-arithmetic model to understand key roles, then explain why the model is not a secure real-world encryption scheme.

35 min Video by Computerphile Security and Error Detection
Prime Numbers & RSA Encryption Algorithm - ComputerphileCurated by Kepler, not produced by us. Watch it before the notes below.
Open on YouTube

Before you start

  • Calculate a remainder and interpret a modular inverse condition.
  • State the permitted raw integer-message domain before encoding arbitrary data.

Watch, pause, try

Video by Computerphile. This general Computerphile explanation develops primes and RSA arithmetic. Pearson’s written lesson keeps the tiny calculations explicitly insecure and separates the raw operation from complete encryption/signature schemes. Use the primary PKCS #1 reference for that distinction; no small classroom key or successful round trip establishes practical security.

Viewing focus: Explain the role of primes and public/private parameters

After watching, attempt these questions before opening the answers. You can also use the written lesson below.

After watching 1: For a new insecure toy system use p=7,q=11,n=77,e=7,d=43. Verify e×d modulo (p−1)(q−1), encrypt message 9 with m^e mod n and recover it. Explain why publicly displaying the prime factors is compatible with a teaching example but not a secure private-key claim.

Show answer and reasoning

The product e×d=301 has remainder one modulo 60. Message 9 encrypts to 37, and 37^43 mod 77 recovers 9. The deliberately small, openly factored modulus lets the exercise be checked; it supplies no resistance to recovering the private operation. Correct modular arithmetic and suitable real cryptographic parameters/encoding are separate issues.

After watching 2: In that raw system, can every possible byte value be passed directly as one permitted message? If the same message is encrypted twice by the deterministic raw operation, what relationship remains visible, and what additional design questions do padding and authenticated key distribution address?

Show answer and reasoning

The raw domain is 0≤m<77, so values such as 255 are outside it. Repeating the same permitted integer produces the same raw ciphertext, revealing equality. Real schemes require suitable message encoding/padding and parameters rather than this deterministic classroom operation. Authenticated key distribution separately establishes which recipient owns a public key; neither padding nor a round trip alone answers every trust question.

What you'll be able to do

  • Explain the role of primes and public/private parameters
  • Trace a small RSA encryption/decryption example
  • Distinguish raw arithmetic from secure key establishment and complete schemes
1

Build an explicitly insecure teaching key

Choose distinct primes p=5 and q=11. Their product n=55 is the modulus, and (p−1)(q−1)=40. Choose public exponent e=3, coprime with 40, and d=27 because 3×27=81 is congruent to 1 modulo 40. The public arithmetic pair is (n,e); the private capability depends on secret information including d in this model.

These values are intentionally tiny so every step can be checked by hand. They can be factored immediately and must never be used to protect real data. The lesson explains why prime structure helps define inverse operations; it does not claim that publishing the two prime factors is compatible with a secure private key.

2

Trace the permitted message domain

For this raw teaching operation, an encoded message is an integer m with 0≤m<n. Compute ciphertext c=mᵉ mod n, then recover m=cᵈ mod n. For m=7, 7³=343 and 343 mod 55=13. The inverse modular exponent gives 7 again. A full byte or arbitrary text string is not automatically a valid single message under modulus 55.

Python’s three-argument pow computes modular exponentiation directly. It avoids first constructing the unrestricted huge power in this demonstration. Independent fixtures check all 55 permitted messages, including zero and messages sharing a factor with n, rather than testing only the convenient value seven. A round trip is evidence for the arithmetic example, not evidence that a cryptographic design is secure.

Python 3
p, q = 5, 11
n = p * q
phi = (p - 1) * (q - 1)
e, d = 3, 27
assert (e * d) % phi == 1
message = 7
ciphertext = pow(message, e, n)
recovered = pow(ciphertext, d, n)
print(n, ciphertext, recovered)
print(all(pow(pow(value, e, n), d, n) == value for value in range(n)))
Scroll horizontally to see the full code or table.
Tiny, deterministic textbook arithmetic only; not a production encryption implementation.
3

Explain the complete security context

Practical RSA encryption and signature schemes require appropriate parameters, encoding/padding, randomness where specified and careful implementation. Raw textbook exponentiation is deterministic and has structural weaknesses. Encryption and signing are different complete schemes, not interchangeable instructions to “encrypt with either key” for any purpose.

RSA-based transport of a small symmetric secret can appear in a suitably defined complete protocol, but secure recipient authentication is still necessary. The TLS 1.3 teaching flow elsewhere uses ephemeral agreement instead of historical RSA key transport. Key compromise, weak random generation, small moduli and implementation mistakes can invalidate a design. In an examination evaluation, link the vulnerability to the relevant mechanism rather than describing public-key cryptography as mathematically unbreakable.

4

Work through the problem

Attempt the task before opening its worked response. Record each change of state, explain the rule used, and check the result against the original requirements. Code examples labelled Python 3 use that language’s conventions; pseudocode states its own assumptions.

Example 1Verify the public/private exponent relationship and encrypt message 7 in the toy system.
13×27=81; 81 mod 40=1.
27³=343; divide by 55 to get remainder 13.
Answer
d is the required inverse for this example; ciphertext is 13.
Example 2Why can this modulus not directly represent every possible one-byte value as a single permitted raw message?
1The permitted integer domain is 0 through 54.
2A byte can represent 0 through 255.
3A complete encoding/scheme cannot be assumed from the tiny arithmetic operation.
Answer
The domains differ; do not treat arbitrary byte/text data as already encoded for this modulus.

Common mistakes to avoid

Treating raw exponentiation as a complete secure encryption system.
Distinguish the primitive from a standardised complete scheme.
Encrypting an out-of-domain number and assuming it will recover unchanged.
Encode data into the scheme’s permitted domain and follow its full rules.

Key takeaways

  • Prime-derived structure defines this small inverse calculation.
  • Trace modular exponentiation over a stated domain.
  • Real security needs a complete authenticated scheme and suitable implementation.

Explore further

Return to this tomorrow

Close the notes and answer from memory. Revisit any explanation you cannot yet reconstruct.

  • A successful tiny RSA round trip proves the key is safe for real data:
  • Which is accurate about a modern protocol diagram?

Test yourself

Answer a few questions, then review anything you missed.

Next step

Keep practising

Start with the quiz above to check the key ideas. You can also choose another topic from the practice library.

Browse practice topics

Related lessons

All 3 lessons