It is explained here:
http://en.wikipedia.org/wiki/Cyclic_permutation_of_integer
blackjack
flooble's webmaster puzzle