Defining expansion/permutation function