當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。