这个Problem 2 有点困惑的,我通过程序获得了一组3对线性独立的向量,但是任然不过,过会再继续,但是代码的原理应该是可以的。
choose_rand_vector()返回一个符合要求3个tuple的list
choose_rand_vector(randNum=4,vecLength=6):
choose_pair()验证所有的vector组合是否满足6个向量相互线性独立的要求
def choose_pair():
# 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 *
from vec import *
from itertools import *
## 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):
while True:
u=list2vec([randGF2() for i in range(len(a0.D))])
if a0*u==s and b0*u==t:
return u
## Problem 2
# Give each vector as a Vec instance
secret_a0 = list2vec([one,one,0,one,0,one])
secret_b0 = list2vec([one,one,0,0,0,one])
secret_a1 = list2vec([0, 0, 0, 0, one, 0])
secret_b1 = list2vec([one, one, 0, one, 0, 0])
secret_a2 = list2vec([0, one, 0, one, 0, one])
secret_b2 = list2vec([0, 0, one, 0, one, 0])
secret_a3 = list2vec([one, 0, 0, 0, one, 0])
secret_b3 = list2vec([0, one, one, 0, one, one])
secret_a4 = list2vec([one, one, one, one, 0, 0])
secret_b4 = list2vec([one, 0, one, one, 0, one])
def choose_rand_vector(randNum=4,vecLength=6):
r=[]
r.append(secret_a0)
r.append(secret_b0)
while randNum>0:
u=list2vec([randGF2() for i in range(vecLength)])
r.append(u)
if is_independent(r):randNum-=1
else:r.pop()
return [(r[0],r[1]),(r[2],r[3]),(r[4],r[5])]
def choose_pair():
r=[]
while True:
r1=choose_rand_vector(randNum=4,vecLength=6)
r2=choose_rand_vector(randNum=4,vecLength=6)
r3=r1+r2
r3.remove(r1[0])
r3.remove(r2[0])
r4=list(permutations(r3,2))
r5=[list(r1[0])+list(x[0])+list(x[1]) for x in r4]
for i in r5:
if not is_independent(i):break
return r3
'''
k=choose_pair()
z=[]
k=[list(x) for x in k]
#print(k)
[print(x[0].f.values(),x[1].f.values()) for x in k]
#[print(list(a.f.values())) for a in r]
'''