我正在阅读的书对算法的解释如下:
- 2 人想到 2 个公开的“n 和 g”数字都知道。
- 2 个人想到了他们保密的 2 个私人“x”和“y”数字。
交换发生如图所示
我将以下 python 代码放在一起,看看它是如何工作的,而......它没有。请帮助我了解我缺少什么:
#!/usr/bin/python
n=22 # publicly known
g=42 # publicly known
x=13 # only Alice knows this
y=53 # only Bob knows this
aliceSends = (g**x)%n
bobComputes = aliceSends**y
bobSends = (g**y)%n
aliceComputes = bobSends**x
print "Alice sends ", aliceSends
print "Bob computes ", bobComputes
print "Bob sends ", bobSends
print "Alice computes ", aliceComputes
print "In theory both should have ", (g**(x*y))%n
---
Alice sends 14
Bob computes 5556302616191343498765890791686005349041729624255239232159744
Bob sends 14
Alice computes 793714773254144
In theory both should have 16