I want to solve the following problem:
Let $d$ and $e$, both natural numbers, be each others inverses modulo $\varphi(n)$, where $n = p\cdot q$ is a product of two different prime numbers $p$ and $q$. Let $M = \{0,1,2,\dots,(n-1)\}$ be the set of nonnegative numbers smaller than $n$. Define two functions $f: M \rightarrow M$ and $g: M \rightarrow M$ as \begin{align*} f(x) = x^e \bmod n \quad \mbox{and}\quad g(x) = x^d \bmod n \end{align*} Show that $f(g(x)) = x$ and $g(f(x))= x$ for all $x \in M$.
I understand that $f(x)$ and $g(x)$ will always produce numbers between 0 and $n$, since $x$ is smaller than $n$. In that respect, $f(x) = g(x)$ no matter what $e$ and $d$ we choose.
But I don't understand why $f(g(x)) = x$ and $g(f(x))= x$.