当前位置: 首页>>代码示例>>Python>>正文


Python gmpy2.iroot方法代码示例

本文整理汇总了Python中gmpy2.iroot方法的典型用法代码示例。如果您正苦于以下问题:Python gmpy2.iroot方法的具体用法?Python gmpy2.iroot怎么用?Python gmpy2.iroot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gmpy2的用法示例。


在下文中一共展示了gmpy2.iroot方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: small_e_msg

# 需要导入模块: import gmpy2 [as 别名]
# 或者: from gmpy2 import iroot [as 别名]
def small_e_msg(key, ciphertexts=None, max_times=100):
    """If both e and plaintext are small, ciphertext may exceed modulus only a little

    Args:
        key(RSAKey): with small e, at least one ciphertext
        ciphertexts(list)
        max_times(int): how many times plaintext**e exceeded modulus maximally

    Returns:
        list: recovered plaintexts
    """
    ciphertexts = get_mutable_texts(key, ciphertexts)
    recovered = []
    for ciphertext in ciphertexts:
        log.debug("Find msg for ciphertext {}".format(ciphertext))
        times = 0
        for k in range(max_times):
            msg, is_correct = gmpy2.iroot(ciphertext + times, key.e)
            if is_correct and pow(msg, key.e, key.n) == ciphertext:
                msg = int(msg)
                log.success("Found msg: {}, times=={}".format(i2h(msg), times // key.n))
                recovered.append(msg)
                break
            times += key.n
    return recovered 
开发者ID:GrosQuildu,项目名称:CryptoAttacks,代码行数:27,代码来源:rsa.py

示例2: hastad_unpadded

# 需要导入模块: import gmpy2 [as 别名]
# 或者: from gmpy2 import iroot [as 别名]
def hastad_unpadded(ct_list, mod_list, e):
    """
    Implementing Hastad's Broadcast Attack
    """
    m_expo = crt(ct_list, mod_list)
    if m_expo != -1:
        eth_root = gmpy2.iroot(m_expo, e)
        if eth_root[1] == False:
            print "[+] Cannot calculate e'th root!"
            return -1
        elif eth_root[1] == True:
            return long_to_bytes(eth_root)
    else:
        print "[+] Cannot calculate CRT"
        return -1 
开发者ID:ashutosh1206,项目名称:Crypton,代码行数:17,代码来源:hastad_unpadded.py

示例3: common_modulus

# 需要导入模块: import gmpy2 [as 别名]
# 或者: from gmpy2 import iroot [as 别名]
def common_modulus(e1, e2, n, c1, c2):
	g, a, b = egcd(e1, e2)
	if a < 0:
		c1 = neg_pow(c1, a, n)
	else:
		c1 = pow(c1, a, n)
	if b < 0:
		c2 = neg_pow(c2, b, n)
	else:
		c2 = pow(c2, b, n)
	ct = c1*c2 % n
	m = int(gmpy2.iroot(ct, g)[0])
	return long_to_bytes(m) 
开发者ID:ashutosh1206,项目名称:Crypton,代码行数:15,代码来源:exploit.py

示例4: root

# 需要导入模块: import gmpy2 [as 别名]
# 或者: from gmpy2 import iroot [as 别名]
def root(self, a, e):
  	return (gmpy2.iroot(a,e)) 
开发者ID:lockedbyte,项目名称:cryptovenom,代码行数:4,代码来源:main.py

示例5: factor_prime_power

# 需要导入模块: import gmpy2 [as 别名]
# 或者: from gmpy2 import iroot [as 别名]
def factor_prime_power(x):  # TODO: move this to a separate math/number theory module
    """Return p and d for a prime power x = p**d."""
    if x <= 1:
        raise ValueError('number not a prime power')

    k = 10
    # test whether p is below 2**k, for positive k
    p = 2
    while p < 1<<k:
        if x % p == 0:
            d = 0
            while x > 1:
                x, r = divmod(x, p)
                if r == 0:
                    d += 1
                else:
                    raise ValueError('number not a prime power')

            return int(p), d

        p = next_prime(p)

    # find prime factors of d
    p, d = x, 1
    while is_square(p):
        p, d = isqrt(p), 2*d
    e = 3
    while k * e <= p.bit_length():
        w, b = iroot(p, e)
        if b:
            p, d = w, e * d
        else:
            e = next_prime(e)

    if is_prime(p):
        return int(p), int(d)

    raise ValueError('number not a prime power') 
开发者ID:lschoe,项目名称:mpyc,代码行数:40,代码来源:gmpy.py

示例6: iroot

# 需要导入模块: import gmpy2 [as 别名]
# 或者: from gmpy2 import iroot [as 别名]
def iroot(x, n):
        """Return (y, b) where y is the integer nth root of x and b is True if y is exact."""
        if x == 0:
            return x, True

        k = (x.bit_length() - 1) // n
        y = 1<<k
        for i in range(k-1, -1, -1):
            z = y | 1<<i
            if z**n <= x:
                y = z
        return y, x == y**n 
开发者ID:lschoe,项目名称:mpyc,代码行数:14,代码来源:gmpy.py

示例7: common_modulus

# 需要导入模块: import gmpy2 [as 别名]
# 或者: from gmpy2 import iroot [as 别名]
def common_modulus(e1, e2, n, c1, c2):
    	g, a, b = egcd(e1, e2)
    	if a < 0:
    		c1 = neg_pow(c1, a, n)
    	else:
    		c1 = pow(c1, a, n)
    	if b < 0:
    		c2 = neg_pow(c2, b, n)
    	else:
    		c2 = pow(c2, b, n)
    	ct = c1*c2 % n
    	m = int(gmpy2.iroot(ct, g)[0])
    	return m 
开发者ID:X-Vector,项目名称:X-RSA,代码行数:15,代码来源:RSA_common_modulus.py


注:本文中的gmpy2.iroot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。