Lesson 14 of 15
Shamir's Secret Sharing
Shamir's Secret Sharing
Shamir's Secret Sharing (Adi Shamir, 1979) splits a secret into shares such that any shares can reconstruct the secret, but any shares reveal absolutely nothing. This is called a -threshold scheme.
Construction
- Represent the secret as an integer (the constant term of a polynomial)
- Choose a random polynomial of degree : where is a prime larger than both and
- Give party the share for
Reconstruction — Lagrange Interpolation
Given shares , reconstruct using Lagrange interpolation modulo :
The modular division uses Fermat's little theorem: .
Security
With fewer than shares, the secret is information-theoretically hidden — any value of is equally likely. This is provably secure, unlike computational security assumptions.
Applications
- Distributed key management — split private keys across multiple servers
- Disaster recovery — -of- backup schemes
- Secure multi-party computation — building block for advanced protocols
Our Deterministic Version
For testability, we use deterministic coefficients: (instead of random).
Your Task
Implement:
shamir_share(secret, n, threshold, prime=2**31-1)— generate shares using a degree- polynomialshamir_reconstruct(shares, prime=2**31-1)— Lagrange interpolation to recover the secret
Python runtime loading...
Loading...
Click "Run" to execute your code.