Four players — Red, Green, Yellow, Black — each hold a piece. Any three pieces together recover the secret; any fewer reveal nothing useful.
x = 0
— think of a hidden point (0, S)
.(xᵢ, yᵢ)
on the same curve. Alone it’s useless; together (≥ k) they can “connect the dots.”(x, y)
.x = 0
.Under the hood, Shamir uses arithmetic “modulo” a big prime number. For this demo we pick a small prime so the math fits on a napkin. The shares below are auto‑computed from a hidden polynomial. Try selecting any 3 players to reconstruct the secret!
We work in a finite field modulo prime p
. We pick a secret S
and a random polynomial of degree k−1
with constant term S
. For k = 3
we use a quadratic:
f(x) = S + a₁·x + a₂·x² (mod p)
Each share is (xᵢ, yᵢ = f(xᵢ))
. To recover the secret from any 3 shares, we use Lagrange interpolation at x=0
:
S = f(0) = Σ yᵢ · Lᵢ(0) (mod p)
, where Lᵢ(0) = Πj≠i (0 − xⱼ) · (xᵢ − xⱼ)⁻¹ (mod p)
.
Don’t worry if that looks intense: the button does it for you.