写在前面:html
任何大师所发明的都是通用的规律,而不是赋予表象的技巧:python
高斯的“正十七边形尺规做图法”是表象,而尺规做图的加法器、乘法器、开根器是通用规律,更核心的是如何将正多边形的角度转换成开根式。ios
废话很少,进入正题:bash
运行结果:dom
****************************************************
J_bob = 5 ; I_alice = 5
transfer_to_alice 1375
range_list [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Yu_list [ 1355, 1340, 1967, 32, 473, 758, 2051, 26, 883, 537]
Zu_list [ 71, 56, 41, 32, 45, 9, 18, 26, 27, 2]
list_back_to_bob [ 71, 56, 41, 32, 45, 10, 19, 27, 28, 3]
list[J_bob - 1] = list[4] = 45
G = x_random_bob % p_alice_for_bob = 45
result: Bob <= Alice
****************************************************
J_bob = 7 ; I_alice = 5
transfer_to_alice 1373
range_list [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Yu_list [ 125, 2110, 1355, 1340, 1967, 32, 473, 758, 2051, 26]
Zu_list [ 18, 77, 71, 56, 41, 32, 45, 9, 18, 26]
list_back_to_bob [ 18, 77, 71, 56, 41, 33, 46, 10, 19, 27]
list[J_bob - 1] = list[6] = 46
G = x_random_bob % p_alice_for_bob = 45
result: Bob > Alice
****************************************************
J_bob = 3 ; I_alice = 5
transfer_to_alice 1377
range_list [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Yu_list [ 1967, 32, 473, 758, 2051, 26, 883, 537, 1110, 1428]
Zu_list [ 41, 32, 45, 9, 18, 26, 27, 2, 40, 37]
list_back_to_bob [ 41, 32, 45, 9, 18, 27, 28, 3, 41, 38]
list[J_bob - 1] = list[2] = 45
G = x_random_bob % p_alice_for_bob = 45
result: Bob <= Alice
Process finished with exit code 0
实现代码:wordpress
def map_list_5_str(list_in):
ready_list = list(map(lambda x: '%5s' % str(x), list_in))
r_str = ','.join(ready_list)
return '[' + r_str + ']'
# public key of alice as e, and private key as d, total encode space is N
e_alice = 79
d_alice = 1019
N_alice = 3337
o1 = 1
o2 = 10
I_alice = 5
for J_bob in [5, 7, 3]:
print "\n****************************************************"
print "J_bob =", J_bob, "; I_alice =", I_alice
assert o1 < I_alice < o2
assert o1 < J_bob < o2
# ------------------------------
x_random_bob = 473 # bob's random number
c = (x_random_bob ** e_alice) % N_alice
transfer_to_alice = c - J_bob
print 'transfer_to_alice', transfer_to_alice
range_alice = [1, o2 - o1 + 1]
range_list = range(range_alice[0], range_alice[1] + 1)
print 'range_list ', map_list_5_str(range_list)
Yu_list = [((transfer_to_alice + u) ** d_alice) % N_alice for u in range_list]
print 'Yu_list ', map_list_5_str(Yu_list)
p_alice_for_bob = 107
assert p_alice_for_bob < N_alice
Zu_list = list(map(lambda x: x % p_alice_for_bob, Yu_list))
print 'Zu_list ', map_list_5_str(Zu_list)
list_back_to_bob = Zu_list[0:I_alice]
list_back_to_bob.extend(list(map(lambda x: x + 1, Zu_list[I_alice:])))
print 'list_back_to_bob', map_list_5_str(list_back_to_bob)
g = x_random_bob % p_alice_for_bob
g_ = list_back_to_bob[J_bob - 1]
print ' list[J_bob - 1] = list['+str(J_bob - 1)+'] =', g_
print 'G = x_random_bob % p_alice_for_bob =', g
print 'result:', 'Bob <= Alice' if g >= g_ else 'Bob > Alice'
参考:spa
一种有意思的想法
先在一不透光试管中加入未知量的水
A女士量取她年龄那么多毫升的1mol/L的HCl 加入试管
B女士量取她年龄那么多毫升的1mol/L的NaOH 加入试管
用Ph试纸就可判断谁的年龄大了