Files @ db65075fe7e0
Branch filter:

Location: Shamira/src/shamira.py - annotation

Laman
reconstructing the secret
import os

import gf256


def shareByte(secretB,k,n):
	assert n<255
	coefs=[int(secretB)]+[int(b) for b in os.urandom(k-1)]
	points=[gf256.evaluate(coefs,i) for i in range(1,n+1)]
	return points


def generate(secret,k,n):
	shares=[shareByte(b,k,n) for b in secret]
	return [(i+1, [s[i] for s in shares]) for i in range(n)]


def reconstruct(*shares):
	k=len(shares)
	secretLen=len(shares[0][1])
	res=[None]*secretLen
	for i in range(secretLen):
		bs=[(x,s[i]) for (x,s) in shares]
		res[i]=(gf256.getConstantCoef(k,*bs))
	return bytes(res)