Say I have Alice and Bob:
Alice has $XA$, $YA = g^{XA} \bmod P$, $RA$ (random number)
Bob has $XB$, $YB = g^{XB} \bmod P$, $RB$ (random number)
Assume they have exchanged their certificates and they perform the following exchange.
\begin{align} A\to B&:y_B^{RA}\\ B\to A&:y_A^{RB} \end{align}
The shared key is $Z_{AB}=g^{RA+RB}$
I am trying to make sense of how they will be able to come to the shared key.
If I am bob I derive the key by:
$(YB^{RA})^{XB^{-1}} = ({g^{XB}}^{RA})^{XB^{-1}} = g^{RA}$
The I issue I am facing is the ${g^{XB}}^{RA}$ is actually ${g^{XB}}^{RA} \bmod P$ so how do I remove the $XB$ from $({g^{XB}}^{RA} \bmod P)$ to get $g^{RA}$
EDIT:
To make it more clear using numbers:
Say: $XB =4 ,g=9,P =23,RA=6$
Alice sends bob: \begin{align} A\to B:&y_B^{RA}\\ &y_B^{RA} \bmod P = 16^{6} \bmod 23 =12 \\ \end{align}
How would bob extract the $RA$ from 12???
Bob can try:
$(YB)^{RA\cdot XB^{-1}} = (16)^{RA \cdot 1/4} mod 23$
As can be seen above how i extract the value of RA?? in terms of $g^{RA}$ and there has to be only one answer if not how would bob know the which answer alice is using? Does it matter which answer alice is using?