The fact that a nontrivial factor usually appears before a full return does not say that either event appears soon. Each iteration of the RSA cycling attack is inexpensive, but the number of iterations can be enormous. The multiplicative orders governing returns modulo and need not be small, and writing down a large return exponent does not provide a fast way to search the preceding iterations.
If this procedure factored arbitrary well-generated RSA cryptosystem moduli in feasible time with substantial success, it would solve the associated integer factorization problem efficiently. If it instead rapidly returned the predecessor of a ciphertext without factoring, it would solve the RSA inversion problem. Both are intended to be infeasible for appropriate parameters. Efficient integer factorization certainly breaks RSA cryptosystem security; the reverse implication for general RSA inversion problem algorithms is not known.
Thus the stated observation alone provides no serious general attack on well-generated parameters. It also does not prove a lower bound: special moduli or messages with short cycles can be weak, and the hardness claims are computational assumptions.
Avoid constructing the huge integers explicitly. Maintain and , computing after each step.
In case (1), the nontrivial greatest common divisor is one of the prime factors . Divide by it, compute with the extended Euclidean algorithm, and return .
In case (2), . The preceding value satisfies . Cubing is a bijection on the residue classes modulo , so there is only one such cube root, namely the original plaintext . Therefore
For , the preceding value is ; a fixed point is its own plaintext. Keeping the previous iterate makes the recovery immediate once the RSA cycling attack succeeds.