Fix two bugs in the suffix permutation code.

- Fixes an off-by-one error when measuring the suffix length, and
  adds an assert to sanity check this behavior.
- Fixes the backtracking implementation; the previous implementation
  would fail to test all possible permutations in some cases.