def isPrimeNumber( n ): if g.zhangConjecturesAllowed and n < 1543267864443420616877677640751301: return isPrimeMillerRabin( int( n ) ) elif n < 3317044064679887385961981: return isPrimeMillerRabin( int( n ) ) else: debugPrint( 'primality testing of ' + str( int( n ) ) ) return 1 if gmpy2.is_bpsw_prp( int( n ) ) else 0
def isprime(self, args): self.check_args(len(args), 1, 1) value = self.interpreter.visit(args[0]) result = gmpy2.is_bpsw_prp(int(value)) result = TextResult(str(result)) print(result.text) return result
def prime_gen(bits: int) -> Generator: """ Create a generator of random prime numbers of size `bits` and begin generating prime numbers """ while True: # create an odd number of size `bits` n = random.getrandbits(bits) | 1 while not gmpy2.is_bpsw_prp(n): # next odd number n += 2 yield n
def generate_prime(bit_count: int, rand_state: int) -> int: # temp = 0 temp = gmpy2.mpz_rrandomb(rand_state, bit_count) while not gmpy2.is_bpsw_prp(temp): # Strong Prime Check temp = gmpy2.mpz_rrandomb(rand_state, bit_count) return temp
def isprime(n): if (not is_bpsw_prp(n)): raise Exception("Not Prime")
def random_prime(bytes=512): p = random.getrandbits(bytes) | 1 while not gmpy2.is_bpsw_prp(p): p = random.getrandbits(bytes) | 1 return p