This calculates all possible permutations of elements in $Z_k$ of length $degree$. If degenerate is true, it loops through all of them, removing the non-degenerate ones (that is, those where $x_i =/= x_i+1$ for all $i=0,...,degree-1$, for an element $x=(x_i)_0^degree)$).