Here's a basic understanding I have of how RSA works from my notes.
Alice generates two primes $p$ and $q$ such that $n= pq$ and finds a $k$ such that $gcd(k,(p-1)(q-1))=1$.
She then finds an s such that $ks \equiv 1 (mod\space (q-1)(p-1))$ and publishes $(k,n)$.
Bert wants to send a message $M$. So he computes $M^k \equiv M^*$ (mod n).
Then Alice computes $(M^*)^s (mod \space n) $ to get the message.
The proof that I have that $(M^*)^s \equiv M (mod \space n) $ is as follows.
$(M^*)^s \equiv M^{sk} (mod \space n) $
$sk \equiv 1 \space (mod \space (p-1)(q-1))$
so $sk= l (p-1)(q-1) + 1$ where $l$ is an integer
Then $M^{sk} \equiv M $ (mod p) and $M^{sk}\equiv M $ (mod q)
Then because $p$ and $q$ are coprime
$M^{sk}\equiv M $ (mod n)
What I don't understand is that if $M^{sk}\equiv M $ (mod p) and $M^{sk}\equiv M $ (mod q) then to get $M$ why can't Alice simply compute $M^{sk} $ (mod p) or $M^{sk} $ (mod q) to get the message M, instead of computing $M^{sk}$ (mod n)? I tried this with an example but $M^{sk} $ (mod p), $M^{sk} $ (mod q) and $M^{sk} $ (mod n) all yield different results. Shouldn't they all give the same result?
If we know $x\bmod p$ and $x\bmod q$, we can uniquely determine $x\bmod pq$. This is the essence of the Chinese Remainder Theorem. For example if $p=5$, $q=11$ and we know $x\equiv 2\pmod 5$ and $x\equiv 9\pmod{11}$, then we must have $x\equiv 42\pmod{pq}$. You can use the extended Euclidean algorithm to obtain the $42$ result. In practice we compute $x^s\bmod {pq}$ directly because the extended gcd would just mean an additional step.