a permutation algorithm about characters