Math & Science 9 min read • Published 2026-03-29

Discrete Mathematics & Cryptographic Number Theory: Permutations, Prime Factors, Modulo Clock Arithmetic, and Vectors

A deep architectural guide to computer science mathematics: factorial explosion, permutation vs combination algorithms, modular congruence in asymmetric cryptography, and 3D Euclidean vector cross products.

Combinatorics: Permutations (nPr) vs. Combinations (nCr)

Combinatorics is the branch of discrete mathematics that deals with counting, arrangement, and structural grouping. In software engineering, choosing between permutations and combinations dictates algorithmic time complexity:

  • Permutations (Order Matters): Used when sequence determines identity, such as arranging passwords, PIN codes, or process scheduling.
    nPr = n! / (n - r)!
  • Combinations (Order Does NOT Matter): Used when grouping elements where order is irrelevant, such as lottery numbers, team selection, or poker hands.
    nCr = n! / (r! × (n - r)!)

Because factorials ($n!$) grow faster than exponential functions, computing large combinations in standard 64-bit IEEE floating-point numbers triggers overflow above $170!$. Modern web utilities leverage JavaScript's native BigInt primitive to evaluate arbitrarily large combinatoric values without loss of precision.

Modular Arithmetic: The Foundation of Modern Cryptography

Modular arithmetic (often called "clock arithmetic") evaluates numbers by their remainder after division by an integer modulus $m$. Two integers $a$ and $b$ are congruent modulo $m$ ($a equiv b pmod m$) if their difference is an exact multiple of $m$:

// Example: 253 mod 60 = 13 (253 = 60 × 4 + 13)

Modular arithmetic forms the mathematical cornerstone of public-key cryptography (RSA, Diffie-Hellman, and Elliptic Curve Cryptography). Its power relies on one-way trapdoor functions: modular exponentiation is computationally trivial in the forward direction:

c = (m^e) mod n // Computed in milliseconds using square-and-multiply

However, reversing this operation (finding the discrete logarithm $m$ given $c, e, n$) requires exponential time when $n$ is a large 2048-bit or 4096-bit semiprime, securing worldwide banking and SSL/TLS communications.

Linear Algebra & Euclidean Vector Mechanics (Dot vs. Cross Product)

In physics engines, 3D graphics rendering (WebGL/WebGPU), and game development, vectors represent directional quantities in spatial dimensions:

  • Dot Product ($mathbf{u} cdot mathbf{v}$): Computes a single scalar value. If the dot product is zero, the two vectors are orthogonal (perpendicular 90°):
    u · v = (u_x × v_x) + (u_y × v_y) + (u_z × v_z) = |u| × |v| × cos(θ)
  • Cross Product ($mathbf{u} imes mathbf{v}$): Computes a new 3D vector that is perpendicular to both original vectors, forming the surface normal vector vital for 3D lighting and polygon shading:
    u × v = [ (u_y*v_z - u_z*v_y), (u_z*v_x - u_x*v_z), (u_x*v_y - u_y*v_x) ]

Perform precise discrete mathematics and linear vector algebra locally with our Permutations & Combinations Solver, Modular Arithmetic Calculator, and 2D & 3D Vector Math Calculator.

Try the Related Tools: