HMWK 02

Cryptographic Primitives, Caesar Cipher & Statistical Cryptanalysis

Statistics in Cybersecurity • Sapienza Università di Roma

Back to Home

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

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 Analysis

Because 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, IN or trigrams like THE, 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 is 26! ≈ 4 × 1026.
Letter Frequency Distribution
Ciphertext vs. English Expected Frequency
χ² Goodness-of-Fit across 26 Shifts
Minimum χ² identifies the correct key

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

Restricted Key Space vs. Structural Design Weaknesses

  • Weaknesses from Restricted Key Space: Even if the true secp256k1 prime field p = 2256 - 232 - 977 is used, restricting the private key k to a small interval [1, B] allows attackers to recover k in O(B) via brute-force or O(√B) via Baby-Step Giant-Step / Pollard's Kangaroo algorithm.
  • Weaknesses from Toy Scheme Design:
    1. Deterministic Character-by-Character Encryption (Electronic Codebook Mode): If a toy scheme encrypts each letter deterministically without a fresh random ephemeral scalar r per 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!
    2. Ephemeral Nonce Reuse: In EC-ElGamal, reusing the same ephemeral scalar r across two messages M1 and M2 yields C2,1 - C2,2 = M1 - M2, leaking the relationship between plaintexts without needing the private key.
    3. 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.

Baby-Step Giant-Step (BSGS) Key Recovery & Automated Decryption