def _testShamir(self, minimum, shares, prime, secret): if self.debug >= 10: print("testShamir(minimum=%d,shares=%d,prime=%d,secret=%d)" % (minimum, shares, prime, secret)) shamir = Shamir(minimum, prime) shamir.setSecret(secret) shamir.randomizeKeys(shares, self.rng) keys = [shamir.getKey(i) for i in range(1, shares + 1)] for t in range(100): self._testShamirRecover(minimum, shares, prime, secret, keys)
def _testShamirRecover(self, minimum, shares, prime, secret, keys): if self.debug >= 100: print( "testShamirRecover(minimum=%d,shares=%d,prime=%d,secret=%s,keys=%s)" % (minimum, shares, prime, secret, keys)) shamir = Shamir(minimum, prime) choices = list(range(shares)) for k in range(minimum): i = self.rng.next(len(choices)) shamir.setKey(choices[i] + 1, keys[choices[i]]) del choices[i] assert shamir.getSecret() == secret for i in range(shares): assert shamir.getKey(i + 1) == keys[i]