We describe a surrogates algorithm for symbolic time series which consists of constrained permutation of strings and exactly preserves the nth-order Markov properties of the original data. In the context of hypothesis tests, each surrogate generated by the algorithm provides another realisation of the same Markov process posited in the null hypothesis. We prove uniformity, convergence and range, and validate numerically the properties of the algorithm with traditional hypothesis tests. Finally we apply it to real-world data from U.S. business cycles. The swapping algorithm can also be interpreted as a constrained realisation of a random walk in a network.