Diffie–Hellman key exchange

I wanted to understand the concept of PKI and how a public key can verify a signature of a private key so I wrote this from the wikipedia example to see the math, so to speak.

//Diffie–Hellman key exchange
//given a calculated prime and primitive root.

var prime              = 23,
    primativeRoot      = 5,
    nickPrivate        = Math.floor(Math.random()*10),
    andrewPrivate      = Math.floor(Math.random()*10),
    nickPublic         = Math.pow(primativeRoot, nickPrivate)%prime,
    andrewPublic       = Math.pow(primativeRoot, andrewPrivate)%prime,
    nickSharedSecret   = Math.pow(andrewPublic, nickPrivate)%prime,
    andrewSharedSecret = Math.pow(nickPublic, andrewPrivate)%prime;
    console.log('nick: knows %s & andrew knows %s', nickSharedSecret, andrewSharedSecret);