The public values cross the wire, then each side raises the other value to its own secret. Both ladders land on the same toy shared value.

highlighted = computed this step

Why the same secret appears twice

Alice receives B and raises it to her secret a. Bob receives A and raises it to his secret b.

Ba=AbB^a=A^b
Public DH exchangeOnly public values cross the wire.Public values on the wireAlicekeeps acomputes sharedBobkeeps bcomputes sharedA seq=8 public valueB seq=19 public value

Only public values cross

The flow shows A=8 crossing to Bob and B=19 crossing to Alice.

A=8,B=19A=8,\quad B=19
Public DH exchangeOnly public values cross the wire.Public values on the wireAlicekeeps acomputes sharedBobkeeps bcomputes sharedA seq=8 public valueB seq=19 public value

Alice computes the shared value

Alice computes B to the a power modulo p, which gives 2.

196mod23=219^{6}\bmod{}23=2
Alice computes sharedThe modular exponentiation ladder is recomputed from exact DH inputs.Alice computes shared - 19^6 mod 23stepbitpriorsquaremultiplyresult01111919111916552052skip2

Bob computes the same value

Bob computes A to the b power modulo p, and he also gets 2.

815mod23=28^{15}\bmod{}23=2
Bob computes sharedThe modular exponentiation ladder is recomputed from exact DH inputs.Bob computes shared - 8^15 mod 23stepbitpriorsquaremultiplyresult01118811818662161312123112622

Summary

Both sides land on shared value 2. NOTE: toy-modulus; no-side-channel; no-production; never-roll-your-own. Exact arithmetic on a deliberately tiny toy modulus; real DH uses 2048+ bit groups inside authenticated reviewed protocols.

Ba=Ab=2B^a=A^b=2
Shared secret checkDiffie-Hellman exchange values recomputed from the toy modulus.Shared secret check - shared=2quantityvaluep23g5a (secret)6A=g^a mod p8b (secret)15B=g^b mod p19shared=B^a=A^b2A^b mod p2