本文整理汇总了Python中BitVector.test_for_primality方法的典型用法代码示例。如果您正苦于以下问题:Python BitVector.test_for_primality方法的具体用法?Python BitVector.test_for_primality怎么用?Python BitVector.test_for_primality使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitVector
的用法示例。
在下文中一共展示了BitVector.test_for_primality方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import test_for_primality [as 别名]
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:
print("\nExperiments with primality testing. If a number is not prime, its primality " +
"test output must be zero. Otherwise, it should a number very close to 1.0.")
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_random_bits(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 test_for_primality [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: