def radix_4(A,B,p):
V=(B&1)*A
U=2*A%p
A=4*A%p
B=B>>1
print("V0:%X"%V)
print("U0:%X" % U)
print("A0:%X" % A)
print("B0:%X" % B)
i=0
while B!=0:
print("B%d:%X" % (i, B))
b1=B&1
B=B>>1
b2=B&1
B=B>>1
V=(V+b1*U+b2*A)%p
U=2*A%p
A=4*A%p
i=i+1
return V
if __name__ == '__main__':
a=0x8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFA3
b=0x8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC1
p=0x8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC3
s_rignt=a*b%p
s_radix4=radix_4(a,b,p)
print("%X"%s_rignt)
print("%X"%s_radix4)
if s_rignt==s_radix4:
print("****计算正确****")
else:
print("####计算错误####")
radix_4算法python实现
最新推荐文章于 2024-11-09 18:29:17 发布