本文整理汇总了Python中gmpy.mpz方法的典型用法代码示例。如果您正苦于以下问题:Python gmpy.mpz方法的具体用法?Python gmpy.mpz怎么用?Python gmpy.mpz使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gmpy
的用法示例。
在下文中一共展示了gmpy.mpz方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import gmpy [as 别名]
# 或者: from gmpy import mpz [as 别名]
def __init__(self, x, radix=2, blocksize=None):
_x_type = type(x)
if _x_type in six.integer_types or _x_type in [_gmpy_mpz_type]:
self._x = gmpy.digits(x, radix)
elif _x_type in [FFXInteger]:
self._x = x._x
elif _x_type in [str]:
self._x = x
elif _x_type in [float, _gmpy_mpf_type]:
self._x = gmpy.digits(gmpy.mpz(x), radix)
else:
raise UnknownTypeException(type(x))
self._radix = radix
if blocksize:
self._blocksize = max(blocksize, len(self._x))
self._x = '0' * (blocksize - len(self._x)) + self._x
else:
self._blocksize = None
self._as_bytes = None
self._as_int = None
self._len = None
示例2: mpz
# 需要导入模块: import gmpy [as 别名]
# 或者: from gmpy import mpz [as 别名]
def mpz( x ):
return x
示例3: powMod
# 需要导入模块: import gmpy [as 别名]
# 或者: from gmpy import mpz [as 别名]
def powMod( x, y, mod ):
"""
(Efficiently) Calculate and return `x' to the power of `y' mod `mod'.
If possible, the three numbers are converted to GMPY's bignum
representation which speeds up exponentiation. If GMPY is not installed,
built-in exponentiation is used.
"""
x = mpz(x)
y = mpz(y)
mod = mpz(mod)
return pow(x, y, mod)
示例4: bytes_to_long
# 需要导入模块: import gmpy [as 别名]
# 或者: from gmpy import mpz [as 别名]
def bytes_to_long(bytestring):
"""Given a ``bytestring`` returns its integer representation ``N``.
"""
N = binascii.hexlify(bytestring)
N = gmpy.mpz(N, 16)
return N
示例5: powMod
# 需要导入模块: import gmpy [as 别名]
# 或者: from gmpy import mpz [as 别名]
def powMod(base, power, modulus):
base = gmpy.mpz(base)
power = gmpy.mpz(power)
modulus = gmpy.mpz(modulus)
result = pow(base, power, modulus)
return compatLong(result)
示例6: _fastgetMP
# 需要导入模块: import gmpy [as 别名]
# 或者: from gmpy import mpz [as 别名]
def _fastgetMP(data, count=1):
mp = []
c = 0
for i in range(count):
length = struct.unpack('!L', data[c:c+4])[0]
mp.append(long(gmpy.mpz(data[c + 4:c + 4 + length][::-1] + '\x00', 256)))
c += length + 4
return tuple(mp) + (data[c:],)
示例7: _fastMP
# 需要导入模块: import gmpy [as 别名]
# 或者: from gmpy import mpz [as 别名]
def _fastMP(i):
i2 = gmpy.mpz(i).binary()[::-1]
return struct.pack('!L', len(i2)) + i2
示例8: _fastMPpow
# 需要导入模块: import gmpy [as 别名]
# 或者: from gmpy import mpz [as 别名]
def _fastMPpow(x, y, z=None):
r = pyPow(gmpy.mpz(x),y,z).binary()[::-1]
return struct.pack('!L', len(r)) + r
示例9: _fastpow
# 需要导入模块: import gmpy [as 别名]
# 或者: from gmpy import mpz [as 别名]
def _fastpow(x, y, z=None):
return pyPow(gmpy.mpz(x), y, z)
示例10: powMod
# 需要导入模块: import gmpy [as 别名]
# 或者: from gmpy import mpz [as 别名]
def powMod(base, power, modulus):
base = gmpy.mpz(base)
power = gmpy.mpz(power)
modulus = gmpy.mpz(modulus)
result = pow(base, power, modulus)
return int(result)
示例11: powMod
# 需要导入模块: import gmpy [as 别名]
# 或者: from gmpy import mpz [as 别名]
def powMod(base, power, modulus):
base = gmpy.mpz(base)
power = gmpy.mpz(power)
modulus = gmpy.mpz(modulus)
result = pow(base, power, modulus)
return long(result)
示例12: _fastgetMP
# 需要导入模块: import gmpy [as 别名]
# 或者: from gmpy import mpz [as 别名]
def _fastgetMP(i):
l = struct.unpack('!L', i[:4])[0]
n = i[4:l+4][::-1]
return long(gmpy.mpz(n+'\x00', 256)), i[4+l:]