本文介绍了关于Diffie-Hellman密钥交换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在阅读的书籍,解释了如下算法:
The book I am reading, explains the algorithm as follows:
- 2人认为2个公共n和g数字
- 2人认为他们保密的是2个私人的x和y号。
交换如图所示
我把下面的python代码放在一起,看看它是如何工作的....它没有,请帮我理解我错了什么: / p>
I put together the following python code to see how this works and .... it does not. Please help me understand what am i missing:
#!/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推荐答案
你忘了两个modulos:
You forgot two more modulos:
>>> 5556302616191343498765890791686005349041729624255239232159744 % 22 16L >>> 793714773254144 % 22 16更多推荐
关于Diffie
发布评论