Intuition, Vocabulary and Foundations
Cryptographic number theory uses easy forward operations whose inverses appear difficult at approved scales. Multiplying primes is easy while factoring their product may be hard; computing $(g^a\bmod p)$ is easy while recovering $(a)$ may be hard in a suitable group. Elliptic curves replace integer multiplication with repeated point addition.
A toy RSA example uses $(p=61)$, $(q=53)$, $(n=3233)$, $(e=17)$, and $(d=2753)$. Message $(65)$ encrypts to $(2790)$ and decrypts correctly, but the modulus is trivially factorable and textbook RSA is deterministic. Diffie–Hellman similarly demonstrates a shared $(g^{ab})$, Rabin demonstrates four square roots, and elliptic curves demonstrate scalar multiplication. None of these bare mechanisms is a secure protocol.
Toy cryptography can demonstrate algebra and failure modes, but cannot establish production security. Real security also requires a threat model, approved parameters, secure randomness, validation, authenticated protocols, side-channel defenses, and audited libraries.
| Concept | Transparent example | Unsafe boundary | Question answered |
|---|---|---|---|
| RSA | $(c=m^e\bmod n)$ | Tiny modulus or textbook encryption | Does the exponent relation round-trip? |
| Diffie–Hellman | Both parties derive $(g^{ab})$ | Tiny group, reused secret, unchecked peer | Is discrete logarithm hard in the validated group? |
| Rabin | $(c=m^2\bmod pq)$ | Assuming decryption has one root | Which of four roots matches the encoding? |
| Elliptic curve | $(Q=kP)$ on a nonsingular curve | Accepting off-curve or wrong-subgroup points | Is the point valid in the intended subgroup? |
| Key material | Uniform secret in the allowed interval | Timestamp or ordinary PRNG output | Is the secret unpredictable and unbiased? |
| Security parameter | Approved curve, modulus, and hash | Ad hoc large-looking numbers | What attack cost and lifetime are targeted? |
| Toy attack | Factor $(3233)$ by trial division | Extrapolating toy work to modern keys | Why do deliberately small parameters fail? |
| Threat model | Active modification and replay included | Testing confidentiality only | Which attacker capabilities are addressed? |
Step-by-Step Derivations and Algorithms
RSA chooses $(n=pq)$, $(e)$ coprime to $(lambda(n))$, and $(d=e^{-1}\bmod\lambda(n))$. Modular exponentiation costs logarithmically many multiplications. Factoring a tiny $(n)$ recovers the private exponent; bounded trial division costs $(O(\sqrt n))$.
Diffie–Hellman publishes $(A=g^a)$ and $(B=g^b)$, then both sides derive $(g^{ab})$. Exhaustive exponent search breaks only the deliberately tiny example. Rabin squares modulo $(pq)$; roots modulo $(p)$ and $(q)$ combine with CRT into four candidates. On $(y^2=x^3+ax+b\pmod p)$, double-and-add computes $(kP)$ in $(O(\log k))$ point operations after curve and point validation.
flowchart TD
A[Choose primitive and threat model] --> B[Validate toy parameters]
B --> C{Educational workflow}
C -->|RSA| D[Round-trip then factor tiny modulus]
C -->|Diffie Hellman| E[Exchange then enumerate tiny exponent]
C -->|Rabin| F[Square then show four roots]
C -->|Elliptic curve| G[Validate then multiply point]
D --> H[Report assumptions and failures]
E --> H
F --> H
G --> H
Each demo preserves its defining algebraic relation and rejects values outside its domain. Forward operations are logarithmic in exponent bits; the bounded toy attacks intentionally use $(O(\sqrt n))$ division or $(O(r))$ enumeration and must remain confined to unsafe teaching parameters.
Implementation, Complexity and Engineering
The code is explicitly TOY_ONLY. It uses fixed tiny parameters and omits standardized padding, authenticated encryption, constant-time execution, secure storage, protocol negotiation, and hardened parsing. Production applications must use maintained high-level cryptographic APIs and operating-system-backed cryptographic randomness.
| Educational choice | Observation | Production failure | Production direction |
|---|---|---|---|
| Tiny RSA modulus | Easy to factor | Private key recovered immediately | Approved sizes, padding, audited API |
| Textbook RSA | Shows exponent relation | Deterministic and malleable | Standard OAEP or PSS APIs |
| Small DH group | Attack can be enumerated | Cheap logs and subgroup attacks | Approved groups, validation, KDF, authentication |
| Fixed secrets | Reproducible trace | Predictable keys | Cryptographic RNG with unbiased sampling |
| Rabin roots | Shows ambiguity | Wrong root selection | Reviewed encoding or standardized construction |
| Affine curve formulas | Readable addition | Timing leakage and exceptional cases | Hardened constant-time library formulas |
| On-curve check | Rejects malformed coordinates | Wrong subgroup may remain | Subgroup validation or safe encodings |
| Round-trip tests | Find functional bugs | Do not prove security | Test vectors, fuzzing, review, and audit |
Applications, Case Studies and Exercises
An approachable suite prints parameters, intermediate identities, successful round trips, and attacks enabled by intentionally unsafe sizes. A professional case study should instead produce an architecture decision record covering threats, approved protocols, key lifetimes, randomness, validation, library selection, updates, and incident response. Every toy primitive must be replaced before deployment.
Apply Educational Cryptography Suite
Case study 1 — break the toys. Run RSA with $(61)$, $(53)$, exponent $(17)$, and message $(65)$; confirm ciphertext $(2790)$, factor $(3233)$, reconstruct the private key, and decrypt. Enumerate the exponent in the $(p=23,g=5)$ DH example. Record work counts and explain why these parameters are intentionally unsafe.
Case study 2 — production migration. Review a prototype using textbook RSA, fixed DH secrets, and custom curve arithmetic. Cover passive observation, modification, replay, key theft, invalid inputs, and timing. For every toy component, name the missing protection and the audited high-level replacement.
Deliverable. Provide rsa-demo, dh-demo, rabin-demo, curve-demo, and bounded attack-toy commands. Every output begins with EDUCATIONAL - NOT FOR PRODUCTION, rejects malformed values, and lists assumptions and failures. Success requires reproducible tests without any custom primitive on a proposed production path.
Use the suite to understand algebra, validation, and attacks—not to protect data. Define the threat model, use standardized protocols and approved parameters, obtain secrets from a cryptographic RNG, validate inputs, avoid custom encodings and arithmetic, and depend on maintained audited libraries.