Changeset - 438dcebc9c63
[Not reviewed]
default
0 1 1
Laman - 7 years ago 2017-09-17 19:29:37

splitting the secret
2 files changed with 27 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/gf256.py
Show inline comments
 
@@ -23,6 +23,15 @@ inv=[E[255-L[i]] if i!=0 else None for i
 

	
 
def ffmul(a, b):
 
	if a==0 or b==0: return 0
 
	t=L[a]+L[b]
 
	if t>255: t-=255
 
	return E[t]
 

	
 

	
 
def evaluate(coefs,x):
 
	res=0
 
	xK=1
 
	for a in coefs:
 
		res^=ffmul(a,xK)
 
		xK=ffmul(xK,x)
 
	return res
src/shamira.py
Show inline comments
 
new file 100644
 
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)]
 

	
 

	
 
print(generate(b"key",2,3))
0 comments (0 inline, 0 general)