Security and Cryptography in Python - Key Exchange(2)

Security and Cryptography in Python - Key Exchange(2)

def is_prime(p):
    for i in range(2, p):
        if p % i == 0:
            return False
    return True

print(is_prime(7))

Running Result:

image-20210214153947929

import math
import random

def is_prime(p):
    for i in range(2, math.isqrt(p)):
        if p % i == 0:
            return False
    return True

def get_prime(size):
    while True:
        p = random.randrange(size, 2*size)
        if is_prime(p):
            return p

print(get_prime(10000))

Running Result:

image-20210214154746699

posted @ 2021-02-14 15:49  晨风_Eric  阅读(58)  评论(0编辑  收藏  举报