Shamir Secret Sharing Calculator

Enter a secret, share count, threshold and prime to generate shares.

How it is calculated

The secret S becomes the constant term of a polynomial of degree k−1: f(x) = S + a1x + … + ak−1xk−1 (mod p). Share number i is the pair (i, f(i)), for i = 1 … n, and any k shares determine the polynomial and so recover S = f(0). Here p is the prime modulus, and the secret must be a whole number from 0 up to p−1.

By default each coefficient a1 … ak−1 is drawn with a cryptographically secure random generator (PHP's random int), uniform over 0 … p−1, as Shamir's scheme requires, so every run gives new shares; the shares are only as safe as that randomness. The other mode, “From the seed”, computes each ai from a CRC-32 checksum of the text “seed#i” taken mod p, so the same inputs and seed always give the same shares. That suits learning and checking by hand, but it is not secure. All numbers must be whole and no larger than about 3 billion. The threshold must be at least 2 and no larger than the share count, the share count must be between 1 and 1,000 and smaller than p, and p must be prime. Any input that breaks these rules shows no result.

Worked example

Secret S = 1234, n = 4 shares, threshold k = 3, prime p = 7919, coefficients “From the seed” with the seed “demo” (the reproducible demo mode, so the numbers can be followed by hand; the default random mode gives new shares each run). The seed gives a1 = 6415 and a2 = 1485, so f(x) = 1234 + 6415x + 1485x² (mod 7919). f(1) = 9134 − 7919 = 1215. f(2) = 20004 − 2×7919 = 4166. f(3) = 33844 − 4×7919 = 2168. f(4) = 50654 − 6×7919 = 3140. The tool lists the shares as:
1: 1215
2: 4166
3: 2168
4: 3140
Any three of them can be combined by Lagrange interpolation to get 1234 back.

Try this example →

Common mistakes

  • Using the seeded demo mode for a real secret. Its coefficients come from a public checksum of the seed, so anyone who knows the seed (for example “demo”) can rebuild the polynomial, and even one share then reveals the secret. The random mode avoids that, but the secret still reaches this site in the page address: split a real secret with an audited tool on your own device.
  • Choosing a modulus that is not prime, such as 7920. The tool rejects it, because division in the recovery step needs a prime field.
  • Entering a secret equal to or larger than the modulus. The secret must be below p, so a 4-digit secret needs a prime above 9999.
  • Making the share count as large as the modulus. Shares are numbered 1 … n and those numbers must be distinct non-zero residues mod p, so n has to be smaller than p; with p = 7, asking for 7 shares shows no result.
  • Setting the threshold to 1 or above the number of shares. Thresholds below 2 give no result, and a threshold above n could never be met.

Sources

  • How to Share a Secret — Adi Shamir, Communications of the ACM 22(11):612-613, 1979 (copy hosted by MIT course 6.857)

About this calculator

Introduced by cryptographer Adi Shamir in 1979, Shamir's Secret Sharing splits a secret into n shares so that any k of them reconstruct it exactly, while — when implemented properly — any k−1 or fewer reveal absolutely nothing about it (information-theoretic, not just computational, security). It works by building a polynomial of degree k−1 whose constant term is the secret, with the other coefficients chosen at random, then handing each participant one point (x, f(x)) on that polynomial, evaluated over a finite field defined by a prime modulus.

Recovery uses Lagrange interpolation: any k of the distributed points uniquely determine the degree-(k−1) polynomial, and evaluating it at x = 0 returns the original secret. This threshold scheme underlies real key-management systems — HashiCorp Vault's unseal keys and wallet-recovery standards like SLIP-0039 use it so that no single key holder, and no small subset of them, can reconstruct a master secret alone. By default this calculator draws the other coefficients with a cryptographically secure random generator, so every run gives new shares, and shares are only as safe as that randomness. A seeded mode gives repeatable shares for learning and is not secure. The secret is sent to this site in the page address, so do not split a real secret here: use an audited tool on your own device.

Was this helpful?

You can pick up to 3 reactions.

Comments

  • Be the first to comment.

Popular calculators

All Calculators