import math
import random
def judge_prime(p): #素数判断
if p <= 1:
return False
i = 2
while i * i <= p:
if p % i == 0:
return False
i += 1
return True
def get_generator(p): #得到所有原根
a = 2
list = []
while a < p:
flag = 1
while flag != p:
if (a ** flag) % p == 1:
break
flag += 1
if flag == (p - 1):
list.append(a)
a += 1
return list
#A,B得到各自的计算数
def get_calculation(p, a, X):
Y = (a ** X) % p
return Y
#A,B得到交换计算数后的密钥
def get_
import random
def judge_prime(p): #素数判断
if p <= 1:
return False
i = 2
while i * i <= p:
if p % i == 0:
return False
i += 1
return True
def get_generator(p): #得到所有原根
a = 2
list = []
while a < p:
flag = 1
while flag != p:
if (a ** flag) % p == 1:
break
flag += 1
if flag == (p - 1):
list.append(a)
a += 1
return list
#A,B得到各自的计算数
def get_calculation(p, a, X):
Y = (a ** X) % p
return Y
#A,B得到交换计算数后的密钥
def get_