本文整理汇总了Python中BitVector.gen_rand_bits_for_prime方法的典型用法代码示例。如果您正苦于以下问题:Python BitVector.gen_rand_bits_for_prime方法的具体用法?Python BitVector.gen_rand_bits_for_prime怎么用?Python BitVector.gen_rand_bits_for_prime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitVector
的用法示例。
在下文中一共展示了BitVector.gen_rand_bits_for_prime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gen_rand_bits_for_prime [as 别名]
bv.shift_right(1)
print(bv)
bv.shift_right(1).shift_right(1)
print(bv)
bv = BitVector( bitlist = (1,1, 1, 0, 0, 1) )
print(bv)
bv.shift_left(1)
print(bv)
bv.shift_left(1).shift_left(1)
print(bv)
# UNCOMMENT THE FOLLOWING LINES TO TEST THE
# PRIMALITY TESTING METHOD. IT SHOULD SHOW
# THAT ALL OF THE FOLLOWING NUMBERS ARE PRIME:
# primes = [179, 233, 283, 353, 419, 467, 547, 607, 661, 739, 811, 877, \
# 947, 1019, 1087, 1153, 1229, 1297, 1381, 1453, 1523, 1597, \
# 1663, 1741, 1823, 1901, 7001, 7109, 7211, 7307, 7417, 7507, \
# 7573, 7649, 7727, 7841]
# for p in primes:
# bv = BitVector( intVal = p )
# check = bv.test_for_primality()
# print("The primality test for " + str(p) + ": " + str(check))
print("\nGenerate 32-bit wide candidate for primality testing:")
bv = BitVector( intVal = 0 )
bv = bv.gen_rand_bits_for_prime(32)
print(bv)
check = bv.test_for_primality()
print("The primality test for " + str(int(bv)) + ": " + str(check))
示例2: BitVector
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gen_rand_bits_for_prime [as 别名]
from BitVector import *
pcheck = 0
qcheck = 0
ev = BitVector(intVal=65537)
pv = BitVector(intVal=0)
qv = BitVector(intVal=0)
n_found = 0
while n_found == 0:
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: