-
Notifications
You must be signed in to change notification settings - Fork 0
/
secret_sharing_lab.py
50 lines (42 loc) · 1.32 KB
/
secret_sharing_lab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# version code 988
# Please fill out this stencil and submit using the provided submission script.
import random
from GF2 import one
from vecutil import list2vec
from independence import is_independent
from vec import Vec
from itertools import combinations
## Problem 1
def randGF2(): return random.randint(0,1)*one
a0 = list2vec([one, one, 0, one, 0, one])
b0 = list2vec([one, one, 0, 0, 0, one])
def choose_secret_vector(s,t):
uFound = False
u = list2vec([0,0,0,0,0,0])
while not uFound:
u = list2vec([randGF2() for i in range(6)])
if a0*u == s and b0*u == t:
uFound = True
return u
## Problem 2
# Give each vector as a Vec instance
secret_a0 = a0
secret_b0 = b0
secret_a1 = Vec(a0.D, {})
secret_b1 = Vec(a0.D, {})
secret_a2 = Vec(a0.D, {})
secret_b2 = Vec(a0.D, {})
secret_a3 = Vec(a0.D, {})
secret_b3 = Vec(a0.D, {})
secret_a4 = Vec(a0.D, {})
secret_b4 = Vec(a0.D, {})
vecList = [(secret_a1, secret_b1), (secret_a2, secret_b2), (secret_a3, secret_b3), (secret_a4, secret_b4)]
imVecs = [(secret_a0, secret_b0)]
notFound = True
while notFound:
for vecPair in vecList:
for vec in vecPair:
for i in range(6):
vec[i] = randGF2()
if all(is_independent(list(sum(x,()))) for x in combinations(vecList +imVecs,3)):
notFound = False