Advertisement
easklund

HA3B2

Dec 3rd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. def countF1of1(poly):
  2. size = len(poly)
  3. summa = 0
  4. for j in range(size):
  5. summa += poly[j]*(1**j)
  6.  
  7. return summa
  8.  
  9. def Fof1(poly, f1):
  10. size = len(poly)
  11. F1 = f1
  12. for j in range(size):
  13. F1 += poly[j]
  14. return F1
  15.  
  16. def revealMasterSecret(listOfKPoly):
  17. #interpolate
  18. #secret = sumOF(f(i)) * multiplicationssummaOF(j(j-i))
  19. #sumOf = 0
  20. secret = 0
  21. size = len(listOfKPoly)
  22. for i in range(size):
  23. mulOf = 1
  24. f = listOfKPoly[i]
  25. for j in range(size):
  26. if j != i :
  27. mulOf = mulOf * (j+1)/((j+1)-(i+1))
  28. secret += (f * mulOf)
  29. return secret
  30.  
  31. def addF1InPoly(f1, poly):
  32. p = []
  33. p.append(f1)
  34. for i in range(len(poly)):
  35. p.append(poly[i])
  36. return p
  37.  
  38. privatepoly = [ 13, 8, 11, 1, 5]
  39. fOf1 = [ 75, 75, 54, 52, 77, 54, 43]
  40. collaberationPoly = [2782, 0, 30822, 70960, 0, 256422]
  41.  
  42. f1Of1 = countF1of1(privatepoly)
  43. fOf1 = Fof1(fOf1, f1Of1)
  44. p = addF1InPoly(fOf1, collaberationPoly)
  45. secret = revealMasterSecret(p)
  46.  
  47.  
  48. print(f1Of1)
  49. print(fOf1)
  50. print(p)
  51. print(secret)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement