inv=inverse_mod(30,1373)
print(30*inv%1373) #1
d,u,v=xgcd(20,30)
print("d:{0} u:{1} v:{2}".format(d,u,v))#d:10 u:-1 v:1
计算参考:
https://blog.csdn.net/destiny1507/article/details/81751168
def chinese_remainder(modulus, remainders):
Sum = 0
prod = reduce(lambda a, b: a*b, modulus)
for m_i, r_i in zip(modulus, remainders):
p = prod // m_i
Sum += r_i * (inverse_mod(p,m_i)*p)
return Sum % prod
chinese_remainder([3,5,7],[2,3,2]) #23
2 x ≡ 13 m o d 23 2^x \equiv13 \mod23 2x≡13mod23
x=discrete_log(mod(13,23),mod(2,23))
#或discrete_log(13,mod(2,23))
print(x)
x 22 ≡ 5 m o d 41 x^{22} \equiv5\mod 41 x22≡5mod41
x=mod(5,41)
r=x.nth_root(22)
print(euler_phi(71)) #70
result=pi^2
result.numerical_approx()
π ( x ) x / I n ( x ) \frac{\pi(x)}{x/In(x)} x/In(x)π(x)
result=prime_pi(1000)/(1000/log(1000))
result.numerical_approx() #1.16050288686900
y 2 = x 3 + a 4 x + a 6 y^2=x^3+a_4x+a_6 y2=x3+a4x+a6输出所有整数点
a4=2;a6=3;F=GF(7);
E=EllipticCurve(F,[0,0,0,a4,a6])
print(E.cardinality()) #6
print(E.points()) #[(0 : 1 : 0), (2 : 1 : 1), (2 : 6 : 1), (3 : 1 : 1), (3 : 6 : 1), (6 : 0 : 1)]
创建点
point1=E([2,1])
point2=E([3,6])
print(point1+point2)#(6 : 0 : 1)
print(point1-point2)#(2 : 6 : 1)