本文整理汇总了Python中sage.rings.all.ZZ.append方法的典型用法代码示例。如果您正苦于以下问题:Python ZZ.append方法的具体用法?Python ZZ.append怎么用?Python ZZ.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.rings.all.ZZ
的用法示例。
在下文中一共展示了ZZ.append方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import append [as 别名]
def __init__(self, params, asym=False):
# set parameters
(self.alpha, self.beta, self.rho, self.rho_f, self.eta, self.bound, self.n, self.k) = params
self.x0 = ZZ(1)
self.primes = [random_prime(2**self.eta, lbound = 2**(self.eta - 1), proof=False) for i in range(self.n)]
primes = self.primes
self.x0 = prod(primes)
# generate CRT coefficients
self.coeff = [ZZ((self.x0/p_i) * ZZ(Zmod(p_i)(self.x0/p_i)**(-1))) for p_i in primes]
# generate secret g_i
self.g = [random_prime(2**self.alpha, proof=False) for i in range(self.n)]
# generate zs and zs^(-1)
z = []
zinv = []
# generate z and z^(-1)
if not asym:
while True:
z = ZZ.random_element(self.x0)
try:
zinv = ZZ(Zmod(self.x0)(z)**(-1))
break
except ZeroDivisionError:
''' Error occurred, retry sampling '''
z, self.zinv = zip(*[(z,zinv) for i in range(self.k)])
else: # asymmetric version
for i in range(self.k):
while True:
z_i = ZZ.random_element(self.x0)
try:
zinv_i = ZZ(Zmod(self.x0)(z_i)**(-1))
break
except ZeroDivisionError:
''' Error occurred, retry sampling '''
z.append(z_i)
zinv.append(zinv_i)
self.zinv = zinv
# generate p_zt
zk = Zmod(self.x0)(1)
self.p_zt = 0
for z_i in z:
zk *= Zmod(self.x0)(z_i)
for i in range(self.n):
self.p_zt += Zmod(self.x0)(ZZ(Zmod(self.primes[i])(self.g[i])**(-1) * Zmod(self.primes[i])(zk)) * ZZ.random_element(2**self.beta) * (self.x0/self.primes[i]))
self.p_zt = Zmod(self.x0)(self.p_zt)