Random permutation of bit strings of length $n$, where $n$ can be any positive integer?

I need an efficient, invertible random permutation of $$n$$-bit strings, defined by a $$128$$-bit key. $$n$$ can be any positive integer from $$6$$ to $$128$$. I have no requirements on the security of the permutation; only that it is random (i.e. that outputs for different keys are uncorrelated).

Many standard algorithms exist for $$n$$ of $$32$$, $$64$$, and $$128$$ bits. I wondered if the Sponge Construction of Keccak could be used to transform such permutations into $$n$$-bit permutations. I understand the sponge construction generates a function of variable input length and arbitrary output length. However, it is not clear that if I use it to generate a function to turn one $$n$$-bit string into another $$n$$-bit string, that that function will encode a random permutation. Does it?

• See "Format Preserving Encryption" for standard ways of doing precisely what you're looking for Jan 17 '19 at 21:44
• Please consider answering your own question if you have found the answer Jan 18 '19 at 8:48

1 Answer

Format Preserving Encryption is the name for a standard way of doing what you are asking. It does a keyed mapping from a (potentially small) domain to itself. It does more than you are asking (it tries to be secure; you specified that you didn't need that), however there should not be an issue with this.

You have already found it yourself, however if you were to ask me which FPE primitive to use, I would have suggested FF1.

(I'm putting this as an answer so you can accept it)