Use KMP to solve the cyclic automorphism problem in O(n).