На обмен ключами Диффи-Хеллмана

Книга, которую я читаю, объясняет алгоритм следующим образом:

2 people think of 2 public "n and g" numbers both are aware of. 2 people think of 2 private "x and "y" numbers they keep secret.

Обмен происходит как показано

enter image description here

Я собрал следующий код 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

Ответы на вопрос(3)

Ваш ответ на вопрос