当前位置: 首页>>代码示例>>Python>>正文


Python Polynomial.evaluate方法代码示例

本文整理汇总了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)
开发者ID:dennismckinnon,项目名称:ShamirSS,代码行数:51,代码来源:ShSS.py

示例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)
开发者ID:gcmcom,项目名称:pyFileFixity,代码行数:6,代码来源:polynomialtest.py

示例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
开发者ID:sirk390,项目名称:shamir,代码行数:8,代码来源:shamir.py


注:本文中的polynomial.Polynomial.evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。