← Back to All Writeups

Discrete Mathematics in Cybersecurity: From Modular Arithmetic to Attack Graph Theory

In day-to-day cybersecurity operations, teams frequently focus on perimeter appliances, firewall rule tuning, and code auditing. Yet all of contemporary cybersecurity rests upon a singular mathematical bedrock: discrete mathematics.

Continuous mathematical domains (such as calculus or real-valued functions) are smooth, predictable, and approximable. Conversely, discrete structures (finite sets, integers, graphs, and boolean relations) introduce sharp discontinuities, non-linearity, and computational hardness that enable the construction of one-way functions: operations that are trivial to compute forward, but computationally infeasible to invert without a secret key.


1. Number Theory and Modular Arithmetic: The Asymmetric Core

Asymmetric cryptography (RSA, Diffie-Hellman, ECDH/Ed25519) operates across the discrete ring of integers modulo $n$ ($\mathbb{Z}_n$).

+-------------------------------------------------------------------------------+
|                      RSA KEY GENERATION MODULAR ARITHMETIC                    |
+-------------------------------------------------------------------------------+
|                                                                               |
|   1. Discrete Prime Selection:        p, q  (Large, random primes)            |
|   2. Working Modulus:                 n = p * q                               |
|   3. Euler's Totient Function:        phi(n) = (p - 1)(q - 1)                 |
|   4. Public Key (Exponent e):         gcd(e, phi(n)) = 1                      |
|   5. Modular Inverse (Private Key d): e * d = 1 (mod phi(n))                  |
|                                                                               |
|   [ Encryption ]:   C = M^e mod n                                             |
|   [ Decryption ]:   M = C^d mod n   (via Extended Euclidean Algorithm)        |
|                                                                               |
+-------------------------------------------------------------------------------+

The asymmetric hardness arises from discrete integer factorization: computing $n = p \cdot q$ executes in microseconds, whereas deriving $p$ and $q$ from $n$ requires sub-exponential time (General Number Field Sieve), rendering brute-force factorization impossible on 2048/4096-bit keys.


2. Combinatorics and Discrete Probability: The Birthday Attack

For an $n$-bit cryptographic hash function (such as SHA-256 or BLAKE3), there are $2^n$ possible digests. By the Pigeonhole Principle, hashing $2^n + 1$ unique inputs guarantees at least one collision.

However, due to the discrete combinatorics of the Birthday Paradox, an attacker does not need $2^n$ attempts to find an arbitrary collision $H(m_1) = H(m_2)$. A collision probability $> 50%$ occurs at:

$$k \approx \sqrt{2 \cdot 2^n \cdot \ln 2} \approx 1.177 \cdot 2^{n/2} \quad \text{operations}$$

This discrete reality dictates why:

  • 128-bit hashes (MD5) provide only $2^{64}$ collision resistance (broken).
  • Modern standards mandate at least 256-bit digest lengths to ensure an unassailable $2^{128}$ collision security bound.

3. Graph Theory: Attack Paths and Lateral Movement

In offensive (Red Team) and defensive (Blue Team) operations, network architectures, trust relationships, and active directory privilege hierarchies are modeled as Directed Graphs $G = (V, E)$:

  • Nodes $V$: Machine assets, service accounts, and privilege states.
  • Edges $E$: Network access paths, misconfigured ACL permissions, or exploitable trust links.
  • Shortest Path Algorithms (Dijkstra, Bellman-Ford) identify the least-resistance attack route toward domain controller compromise.
  • Min-Cut / Max-Flow Theorems identify the exact minimum set of network connections to sever with firewall rules (OpenBSD PF) to isolate compromised zones.

4. Formal Verification: SAT/SMT Solvers in Protocols

To formally prove that protocols like TLS 1.3 or SSH contain no race conditions or state leakages, protocol states are modeled as discrete boolean propositions evaluated through Linear Temporal Logic (LTL) and SAT/SMT solvers (e.g., Z3) using the DPLL algorithm.


5. Summary

  1. Modular arithmetic guarantees mathematical irreversibility and key derivation.
  2. Combinatorics defines hash security margins and threshold secret sharing (Shamir’s scheme).
  3. Graph theory models attack vectors, lateral movement, and perimeter network isolation.
  4. Formal logic guarantees verified protocol correctness against structural flaws.