(Update 1, 11/11/19: corrected a calculation error)
This is my first time asking a question here.
I was recently watching a video on crashcourse regarding cryptography, and an equation from Diffie–Hellman key exchange came up. The equation from video is :
$$ \left ( B^{x}\bmod C \right )^{y} = \left ( B^{y}\bmod C \right )^{x} = B^{xy}\bmod C $$
But that doesn't sound to be true. Infact, I tried replacing x,y with 2,3 and B,C with 3,7 , which makes the above statement as:
$$\left ( 3^{2}\bmod 7 \right )^{3} | \left ( 3^{3}\bmod 7 \right )^{2} | B^{2*3}\bmod 7$$
$$=\left ( 3^{2}\bmod 7 \right )^{3} | \left ( 3^{3}\bmod 7 \right )^{2} | 3^{2*3}\bmod 7$$
$$=\left ( 9\bmod 7 \right )^{3} | \left ( 27\bmod 7 \right )^{2} | 729 \bmod 7 $$
$$=( 2 )^{3} | ( 6 )^{2} | 1$$
But
$$ 8 \neq 36\neq 1$$
So how is that equation right? I thought that its probably because of the higher precedence of exponential over modular division will be the case and equation would be something like this when expanded:
$$ \left ( B^{xy}\bmod C^{y} \right ) = \left ( B^{yx}\bmod C^{x} \right ) = (B^{xy}\bmod C^{xy}) $$
But that also fails for last case, ie:
$$ \left ( 3^{6}\bmod 7^{2} \right ) = \left ( 3^{6}\bmod 7^{3} \right ) but \neq (3^{6}\bmod 7^{6}) $$
So what's the problem here? is the video claiming a wrong equation or my maths is wrong?
\bmodfor the binary operator;\modgives wrong spacing. – Arturo Magidin Nov 11 '19 at 03:19