Files
@ db65075fe7e0
Branch filter:
Location: Shamira/src/shamira.py - annotation
db65075fe7e0
541 B
text/x-python
reconstructing the secret
438dcebc9c63 438dcebc9c63 438dcebc9c63 438dcebc9c63 438dcebc9c63 438dcebc9c63 438dcebc9c63 438dcebc9c63 438dcebc9c63 438dcebc9c63 438dcebc9c63 438dcebc9c63 438dcebc9c63 438dcebc9c63 438dcebc9c63 438dcebc9c63 438dcebc9c63 db65075fe7e0 db65075fe7e0 db65075fe7e0 db65075fe7e0 db65075fe7e0 db65075fe7e0 db65075fe7e0 db65075fe7e0 | 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)
|