Converting a string into a permutation