Python gmpy.mpz() Examples
The following are 18
code examples of gmpy.mpz().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gmpy
, or try the search function
.
Example #1
Source File: __init__.py From libffx with GNU General Public License v3.0 | 6 votes |
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
Example #2
Source File: common.py From python-for-android with Apache License 2.0 | 5 votes |
def _fastpow(x, y, z=None): return pyPow(gmpy.mpz(x), y, z)
Example #3
Source File: cryptomath.py From plugin.video.vvvvid with GNU General Public License v2.0 | 5 votes |
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)
Example #4
Source File: cryptomath.py From filmkodi with Apache License 2.0 | 5 votes |
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)
Example #5
Source File: common.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def _fastpow(x, y, z=None): return pyPow(gmpy.mpz(x), y, z)
Example #6
Source File: common.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def _fastMPpow(x, y, z=None): r = pyPow(gmpy.mpz(x),y,z).binary()[::-1] return struct.pack('!L', len(r)) + r
Example #7
Source File: common.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def _fastMP(i): i2 = gmpy.mpz(i).binary()[::-1] return struct.pack('!L', len(i2)) + i2
Example #8
Source File: common.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
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:]
Example #9
Source File: cryptomath.py From python-for-android with Apache License 2.0 | 5 votes |
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)
Example #10
Source File: cryptomath.py From python-for-android with Apache License 2.0 | 5 votes |
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)
Example #11
Source File: modexp.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def mpz( x ): return x
Example #12
Source File: common.py From python-for-android with Apache License 2.0 | 5 votes |
def _fastMPpow(x, y, z=None): r = pyPow(gmpy.mpz(x),y,z).binary()[::-1] return struct.pack('!L', len(r)) + r
Example #13
Source File: common.py From python-for-android with Apache License 2.0 | 5 votes |
def _fastMP(i): i2 = gmpy.mpz(i).binary()[::-1] return struct.pack('!L', len(i2)) + i2
Example #14
Source File: common.py From python-for-android with Apache License 2.0 | 5 votes |
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:],)
Example #15
Source File: cryptomath.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
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)
Example #16
Source File: __init__.py From libffx with GNU General Public License v3.0 | 5 votes |
def __init__(self, K, radix): if radix not in range(2, 37): raise InvalidRadixException() self._radix = gmpy.mpz(radix) self._chars = string.digits + string.ascii_lowercase self._chars = self._chars[:radix] _chars = [] for c in self._chars: _chars.append(c) self._chars = _chars self._K = K self._ecb = AES.new(K, AES.MODE_ECB) self._P = {}
Example #17
Source File: __init__.py From libffx with GNU General Public License v3.0 | 5 votes |
def bytes_to_long(bytestring): """Given a ``bytestring`` returns its integer representation ``N``. """ N = binascii.hexlify(bytestring) N = gmpy.mpz(N, 16) return N
Example #18
Source File: modexp.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
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)