Adding permutation and rotation Logic