primitive root to the power privatekey mod Modulus is calculated on both sides
then it is sent accross the channel which is public
It is an NP complete problem so its computationally imfeasible to tell the actual private key given n,a and the mixture which is sent accross
Whatever which is received at Alice end, it is again raised to the power of private key and modded with the modulus and key is calculated at both ends.
This is diffie hellmen key exchange problem
I have also used FERMAT's LITTLE Theorem to compute 3^10mod7 easily
as a^(n-1)modn is 1