I am learning some Cryptography and I came across this exercise where I have to make the following proof (translated from German, so I hope it is accurate).
Proof the following assertion: Let $n \in \mathbb{Z}$ be odd and $a \in \mathbb{Z}_n^*$. If $a^{\frac{n-1}{2}} \neq \pm 1 \mod n$ , then $n$ is a composite.
Now I don't really have any math background, so my proof goes as follows, but I am not sure if I really proofed the assertion:
Proof by contradiction. Assume that $n$ is a composite.
$$a^{\frac{n-1}{2}} \equiv 1 \mod n$$ $$\Rightarrow a^{\frac{n-1}{2}}\cdot a^{\frac{n-1}{2}} \equiv 1 \cdot 1 \mod n$$ $$\Rightarrow a^{n-1} \equiv 1 \mod n$$
Now since $a^{\varphi(n)} \equiv 1 \mod n$ for any finite group and with $\varphi$ being the Euler's totient function. But $\varphi(n) = n - 1$ if and only if $n$ is prime.
And I could do the same thing $a^{\frac{n-1}{2}} \equiv -1 \mod n$