本文整理汇总了Python中polynomial.Polynomial.evaluate方法的典型用法代码示例。如果您正苦于以下问题:Python Polynomial.evaluate方法的具体用法?Python Polynomial.evaluate怎么用?Python Polynomial.evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类polynomial.Polynomial
的用法示例。
在下文中一共展示了Polynomial.evaluate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recover
# 需要导入模块: from polynomial import Polynomial [as 别名]
# 或者: from polynomial.Polynomial import evaluate [as 别名]
def recover(shares, pword=""):
#Intial Stuff
intmod.set_base(59)
#Construct key, If no password is provided, default password of "" is used
seclen=len(shares[0])-1
if pword:
key=genpad(seclen,pword)
else:
key=[intmod(0) for c in xrange(seclen)]
#Catch errors Two keys for the same point
lsh=len(shares)
xs=[intmod(b58conv(shares[i][-1])) for i in xrange(lsh)]
todel=[]
for i in xrange(lsh-1):
for j in xrange(i+1,lsh):
if xs[i]==xs[j]:
if j not in todel:
todel.append(j)
d=0
todel=sorted(todel,reverse=True)
for i in todel:
del xs[i]
del shares[i]
d=d+1
lsh=lsh-d
#Construct the Lagrange Polynomials (These are the same for all elements)
l=[]
for i in xrange(lsh):
lt=Polynomial(x0=intmod(1))
for j in xrange(lsh):
if i != j:
if (xs[i]-xs[j])==intmod(0):
raise ValueError("Two of your keys are for identical points please remedy this")
lt=lt*(Polynomial(x1=intmod(1),x0=-xs[j]))
lt=lt//Polynomial(x0=(xs[i]-xs[j]))
l.append(lt)
#Reconstruct Secret (To best knowledge), Completes Lagrange integration for each character
#Evaluates at 0 and converts into a base 58 character
rect=[]
for i in xrange(seclen):
p=Polynomial(x0=intmod(0))
for j in xrange(lsh):
p=p+Polynomial(x0=(b58conv(shares[j][i])))*l[j]
rect.append(r58conv(p.evaluate(intmod(0))-key[i%64]))
return "".join(rect)
示例2: test_evaluate
# 需要导入模块: from polynomial import Polynomial [as 别名]
# 或者: from polynomial.Polynomial import evaluate [as 别名]
def test_evaluate(self):
a = Polynomial([5,3,1,1,6,8])
e = a.evaluate(3)
self.assertEqual(e, 1520)
示例3: share
# 需要导入模块: from polynomial import Polynomial [as 别名]
# 或者: from polynomial.Polynomial import evaluate [as 别名]
def share(self, secret, threshold, points):
coef = [secret]
coef += [self.field.random() for j in range(threshold-1)]
p = Polynomial(list(reversed(coef)))
shares = [(pt, p.evaluate(pt)) for pt in points]
return shares