关于Diffie

编程入门 行业动态 更新时间:2024-10-26 00:22:14
本文介绍了关于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

本文发布于:2023-11-16 23:14:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607895.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Diffie

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!