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


Python BitVector.gcd方法代码示例

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


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

示例1: create_keys

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gcd [as 别名]
def create_keys():
    #creates the keys
    e = BitVector(intVal = 65537)
    uno = BitVector(intVal = 1)
    tres = BitVector(intVal = 3)#used for checking the last two bits
    generator = PrimeGenerator( bits = 128, debug = 0 )
    p = BitVector(intVal = generator.findPrime())
    while (p[0:2] != tres and int (e.gcd(BitVector(intVal = int(p)-1))) != 1):
        p = BitVector(intVal = generator.findPrime())
    q = BitVector(intVal = generator.findPrime())
    while (q[0:2] != tres and int (e.gcd(BitVector(intVal = int(q)-1))) != 1 and p != q):
        q = BitVector(intVal = generator.findPrime())
    n = int(p) *int( q)
    n = BitVector(intVal = n)
    to = BitVector(intVal =((int(p)-1)*(int(q)-1)))
    d = e.multiplicative_inverse(to)
    d = int(d)
    e = int (e)
    n = int (n)
    p = int (p)
    q = int (q)
    with open('private_key.txt', 'w') as f :
    	f.write(str(d)+"\n")
    	f.write(str(n)+"\n")
    	f.write(str(p)+"\n")
    	f.write(str(q)+"\n")

    with open('public_key.txt', 'w') as f:
    	f.write(str(e)+"\n")
    	f.write(str(n)+"\n")
开发者ID:igalfsg,项目名称:ECE404,代码行数:32,代码来源:generate_keys.py

示例2: create_keys

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gcd [as 别名]
def create_keys():
    #creates the keys
    e = BitVector(intVal = 3)
    uno = BitVector(intVal = 1)
    tres = BitVector(intVal = 3)#used for checking the last two bits
    generator = PrimeGenerator( bits = 128, debug = 0 )
    p = BitVector(intVal = generator.findPrime())
    while (p[0:2] != tres and int (e.gcd(BitVector(intVal = int(p)-1))) != 1):
        p = BitVector(intVal = generator.findPrime())
    q = BitVector(intVal = generator.findPrime())
    while (q[0:2] != tres and int (e.gcd(BitVector(intVal = int(q)-1))) != 1 and p != q):
        q = BitVector(intVal = generator.findPrime())
    n = int(p) *int( q)
    n = BitVector(intVal = n)
    to = BitVector(intVal =((int(p)-1)*(int(q)-1)))
    d = e.multiplicative_inverse(to)
    priv = (d, n, p, q)
    pub = (e,n)
    return (pub, priv)
开发者ID:igalfsg,项目名称:ECE404,代码行数:21,代码来源:flegmann_breakRSA_hw06.py

示例3: print

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gcd [as 别名]
print("\nTesting is_power_of_2_sparse():")
print(bv.is_power_of_2_sparse())                             # False

print("\nTesting reverse():")
bv = BitVector(bitstring='0001100000000000001')
print("original bv: " + str(bv))             # 0001100000000000001
print("reversed bv: " + str(bv.reverse()))   # 1000000000000011000

print("\nTesting Greatest Common Divisor (gcd):")
bv1 = BitVector(bitstring='01100110')
print("first arg bv: " + str(bv1) +
      " of int value: " + str(int(bv1)))  # 102
bv2 = BitVector(bitstring='011010')
print("second arg bv: " + str(bv2) +
      " of int value: " + str(int(bv2)))  # 26
bv = bv1.gcd(bv2)
print("gcd bitvec is: " + str(bv) + " of int value: " + str(int(bv)))  # 2

print("\nTesting multiplicative_inverse:")
bv_modulus = BitVector(intVal=32)
print("modulus is bitvec: " + str(bv_modulus) +
      " of int value: " + str(int(bv_modulus)))
bv = BitVector(intVal=17)
print("bv: " + str(bv) + " of int value: " + str(int(bv)))
result = bv.multiplicative_inverse(bv_modulus)
if result is not None:
    print("MI bitvec is: " + str(result) +
          " of int value: " + str(int(result)))
else:
    print("No multiplicative inverse in this case")
    # 17
开发者ID:gsnedders,项目名称:BitVector,代码行数:33,代码来源:BitVectorDemo.py

示例4: int

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gcd [as 别名]
    if pcheck == 0:
        pv = pv.gen_rand_bits_for_prime(128)
        pcheck = pv.test_for_primality()

    if qcheck == 0:
        qv = qv.gen_rand_bits_for_prime(128)
        qcheck = qv.test_for_primality()

    if (pcheck != 0) and (qcheck != 0):

        n = pv.gf_multiply(qv)
        p = int(pv)
        q = int(qv)
        ptemp = BitVector(intVal=(p - 1), size=128)
        qtemp = BitVector(intVal=(q - 1), size=128)

        if int(ptemp.gcd(ev)) != 1 and int(qtemp.gcd(ev)) != 1:

            pcheck = 0
            qcheck = 0
            n_found = 0

        else:

            n_found = 1

            print "P: " + str(int(pv))
            print "Q: " + str(int(qv))
            print "N: " + str(int(n))
开发者ID:nkumar212,项目名称:ECE404,代码行数:31,代码来源:rand_n_gen.py


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