algorithm to find the order of $a$ in $(\mathbb{Z}/n\mathbb{Z})^*$ where $n$ is not prime.
Now I know a naive algorithm where you just keep multiplying $a$ by itself until you find it equals $1 \mod n$. When $n$ is a prime, there is an easy algorithm as the order of $a$ must divide the size of $(\mathbb{Z}/n\mathbb{Z})^*$, thus we need only search for $\operatorname{ord}_{a}(n)$ in the set of factors of $n$ which is not so hard to find. Does this result somehow extend to non-prime $n$ if you know its prime factorization for instance? Thanks in advance for any help!
EDIT: I know that I do not even need to search for $\operatorname{ord}_a(n)$ if $\gcd (a,n) \neq 1$ in which case the order will be infinite.