# Three-Pass Protocol

I am currently trying to make an example for the three pass protocol. Maybe someone can tell me my mistake, because it doesn't work out. There is no error, but the numbers don't fit.

#Prime p = 8885569519.
#Let a = 7 and b = 17.
#Alice knows K = 263785119.

#Over the Ring mod p-1
R = IntegerModRing(8885569518)
K = 263785120
a = 11
b = 17

#Alice calculates K^a:
Ka = R(K)^a

#Bob calculates (K^a)^b:
Kab = R(Ka)^b

#Alice recives Kab and calculates((K^a)^b)^a^(-1).
#first a^(-1)
y = 1/R(a)
#then y*a % p-1 = 1 (p-1 = 8885569518)
Kaby = R(Kab)^y

#Kaby should be the same as K^b:
Kb = R(K)^b
#but it isn't

#The inverse of b:
z = 1/R(b)
KK = R(Kaby)^z


K^a^b^a^(-1) should be the same as K^b, but it doesn't work out. Does someone see my mistake?

Thank you and best, Luca

edit retag close merge delete

Sort by » oldest newest most voted While your computations for y and z are correctly done (I think) in Z/(p-1), your computations with K need to be done in Z/(p) instead. So add another ring:

R = IntegerModRing(8885569518)
S = IntegerModRing(8885569519)
K = 263785120
a = 11
b = 17

Ka = S(K)^a
(etc.)

y = 1/R(a)
(etc.)

more This post is a wiki. Anyone with karma >750 is welcome to improve it.

I found the problem. It was that if I calculated R(Ka^y) it simply should have been K, but it wasn't. So I tried

  'Kaby = R(K^(a*b*y))'


and this way it works and is the same as Kb. And also

   R(K^(a*y))=K.


So I didn't try your suggestion. But thanks a lot for the response!! :)

more