當前位置: 首頁>>代碼示例>>Python>>正文


Python gmpy.mpz方法代碼示例

本文整理匯總了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 
開發者ID:kpdyer,項目名稱:libffx,代碼行數:26,代碼來源:__init__.py

示例2: mpz

# 需要導入模塊: import gmpy [as 別名]
# 或者: from gmpy import mpz [as 別名]
def mpz( x ):
            return x 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:4,代碼來源:modexp.py

示例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) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:15,代碼來源:modexp.py

示例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 
開發者ID:kpdyer,項目名稱:libffx,代碼行數:10,代碼來源:__init__.py

示例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) 
開發者ID:scalyr,項目名稱:scalyr-agent-2,代碼行數:8,代碼來源:cryptomath.py

示例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:],) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:10,代碼來源:common.py

示例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 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:5,代碼來源:common.py

示例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 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:5,代碼來源:common.py

示例9: _fastpow

# 需要導入模塊: import gmpy [as 別名]
# 或者: from gmpy import mpz [as 別名]
def _fastpow(x, y, z=None):
    return pyPow(gmpy.mpz(x), y, z) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:4,代碼來源:common.py

示例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) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:8,代碼來源:cryptomath.py

示例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) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:8,代碼來源:cryptomath.py

示例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:] 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:6,代碼來源:common.py


注:本文中的gmpy.mpz方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。