1. Toy Cryptographic Scheme based on secp256k1 & EC-ElGamal
Finite Field GF(17) • y² ≡ x³ + 7 (mod 17) • G = (15, 13)In Part 1 of Homework 1, we examined the elliptic curve y² ≡ x³ + 7 (mod 17), which forms a cyclic group of 18 points (17 affine points + the point at infinity ∞). Using base point G = (15, 13) (a generator of full order 18), we build a toy asymmetric encryption scheme analogous to EC-ElGamal.
Algorithm Steps & Key Roles
- Key Generation (Bob): Bob chooses a private scalar
kBfrom a restricted range (e.g.,1 ≤ kB < 18) and computes his public keyQB = kB · G. - Encryption (Alice): To encrypt a message point
M(which is a valid point on the curve representing character encoding or numerical payload), Alice picks a random ephemeral integerr, computes ciphertext componentC1 = r · G, and shared secret maskS = r · QB. The second ciphertext component isC2 = M + S. - Decryption (Bob): Bob receives
(C1, C2). He computes his shared secret maskS' = kB · C1 = kB(rG) = r(kBG) = rQB = S, and recovers the plaintext message point by point subtraction:M = C2 - S' = C2 + (-S').
Interactive EC-ElGamal Simulation
2. The Caesar Cipher & Comparative Analysis
Substitution Cipher • Key Space = 26
The Caesar Cipher is a classic substitution cipher that encrypts plain-text by shifting each letter forward by a fixed number of positions k ∈ [0, 25] modulo 26.
Interactive Caesar Cipher Lab
Comparison: Toy ECC vs. Caesar Cipher
| Cryptographic Feature | Toy ECC Scheme (secp256k1 GF(17)) | Caesar Cipher |
|---|---|---|
| Encryption / Decryption | Algebraic group operations (scalar multiplication & point addition). Relies on Elliptic Curve Discrete Logarithm Problem (ECDLP). | Modular arithmetic letter substitution: C = (P + k) mod 26. |
| Key Space | 18 points/scalars in toy GF(17); real secp256k1 has ~2256 keys. |
26 possible shift keys (extremely small, trivial brute-force). |
| Statistical Properties | High pseudorandomness; output points decorrelate from input coordinates; passes avalanche tests. | Preserves exact plaintext letter frequency distribution (shift invariant); vulnerable to frequency analysis. |
| Security Foundation | Computational hardness of ECDLP (Pollard's rho O(√n)). |
Security by obscurity; zero computational complexity. |
3. Statistical Cryptanalysis of the Caesar Cipher
Chi-Squared Goodness-of-Fit • Letter Frequency AnalysisBecause the Caesar cipher preserves the monographic letter distribution of the underlying language, we can recover the key automatically without brute-forcing all 26 options. By computing the Chi-Squared (χ²) statistic between the decrypted letter counts and known English letter frequencies:
χ² = ∑ (i=A..Z) [ (Oi - Ei)² / Ei ]
The shift key that minimizes χ² corresponds to the correct English plaintext.
Automated Statistical Key Recovery
Effectiveness, Sample Size Limitations & Alternative Approaches
- Effect of Ciphertext Length (Law of Large Numbers): On long and medium texts (>100 characters), the empirical letter distribution converges closely to the theoretical English distribution, producing a sharp, unambiguous minimum in the χ² score at the true shift key. On very short ciphertexts (<15–20 characters), high sampling variance distorts letter counts (e.g., a short phrase lacking common vowels like 'E'), causing the monographic χ² test to occasionally misidentify the correct shift.
- Exhaustive Key Search (Brute-Force): Since the key space is only 26, generating all 26 candidate plaintexts is computationally trivial (
O(26)). However, automated brute-force still requires a statistical scoring function (like χ² or dictionary matching) to recognize the valid plaintext without human visual inspection. - Monogram Frequency vs. N-Gram Scoring: Standard frequency analysis treats letters as independent (unigrams). By contrast, n-gram scoring (bigrams like
TH, HE, INor trigrams likeTHE, AND, ING) evaluates the log-probability of adjacent character sequences:Score = ∑ log P(ci, ci+1). N-gram models capture Markovian language dependencies, making automated key recovery drastically more reliable on short ciphertexts and essential against general monoalphabetic substitution ciphers where the key space is26! ≈ 4 × 1026.
4. Restricted Key Space Attack on Toy ECC
Baby-Step Giant-Step • Pollard's Rho • Exhaustive Search
The toy ECC scheme developed in Part 1 uses the secp256k1 curve equation over GF(17), but restricts the private key k to a small range (e.g., 1 ≤ k < 18) to make experiments computationally feasible.
Key Attack Vectors against Restricted ECC
- Exhaustive Key Search (Brute Force): Because the private key space is only
n = 18, an attacker can simply iteratek = 1, 2, ..., 17, computekG, and match it against the target public keyQin microseconds. - Baby-Step Giant-Step (BSGS): A meet-in-the-middle algorithm that solves the ECDLP in
O(√n)steps. Forn = 18, √18 ≈ 4.2 steps, finding the key almost instantaneously. - Comparison with Caesar Statistical Attack: The Caesar statistical attack exploits redundancy and frequency skew in natural language plaintext. Conversely, the toy ECC restricted key space attack exploits the mathematical structure and small parameter size of the group, completely independent of plaintext language or structure.
- Why Real ECC is Secure: Real-world secp256k1 uses a 256-bit prime group order
n ≈ 1.15 × 1077. Exhaustive search or BSGS would requireO(√n) ≈ 2128operations—computationally infeasible with all physical energy on Earth.
Restricted Key Space vs. Structural Design Weaknesses
- Weaknesses from Restricted Key Space: Even if the true
secp256k1prime fieldp = 2256 - 232 - 977is used, restricting the private keykto a small interval[1, B]allows attackers to recoverkinO(B)via brute-force orO(√B)via Baby-Step Giant-Step / Pollard's Kangaroo algorithm. - Weaknesses from Toy Scheme Design:
- Deterministic Character-by-Character Encryption (Electronic Codebook Mode): If a toy scheme encrypts each letter deterministically without a fresh random ephemeral scalar
rper character, identical plaintext letters map to identical ciphertext points. The ECC scheme degenerates into a simple monoalphabetic substitution cipher and becomes vulnerable to the exact same Chi-Squared frequency analysis used against the Caesar cipher, regardless of how large the private key space is! - Ephemeral Nonce Reuse: In EC-ElGamal, reusing the same ephemeral scalar
racross two messagesM1andM2yieldsC2,1 - C2,2 = M1 - M2, leaking the relationship between plaintexts without needing the private key. - Small Subgroup / Toy Field: Operating over
GF(17)restricts the message space to 18 points, allowing a complete precomputation lookup table (rainbow table) of all possible operations.
- Deterministic Character-by-Character Encryption (Electronic Codebook Mode): If a toy scheme encrypts each letter deterministically without a fresh random ephemeral scalar