本文整理匯總了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:]