Bijective algorithm(s) that can shuffle a range of numbers back and forth I've spent the last hours trying to come up with an algorithm that shuffles an ordered set of numbers (i.e a simple range of numbers) in a way that I can retrieve from a shuffled value the original value that was on that position without the need to store all relationships between shuffled values and their counterparts.

The statement above may not make any sense to you, but I've learned some terms while trying to find such algorithm that may help me to describe what I mean...

First of all I believe that this algorithm/function is bijective, which means it is deterministic and one member of $A$ has only one correspondent member of $B$ and vice-versa:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;


Another peculiarity is that input and output domains are exactly the same so, following the above example, $A$ = $B$ = $D$ with $D$ being a range from $m$ to $n$.

To sum everything up (sorry I'm pretending that I know math):

$D = \{x \in \mathbb N\ | m \le x \le n \}$ 

$
\forall x \in D  \land \forall y \in D\\
f(x) = y \implies \exists  g(y) = x
$

What could be done to simply implement $f$ and $g$ ?

The closest solutions I've found are some kind of block cipher which I'm unable understand nor tweak to achieve the desired behavior which is much simpler.

As one last attempt to explain this, here is a simple use case:


Consider integer codes that can range from 1 to 2^31
On the backend these codes are used sequentially, getting increased one by one
Instead of sending one of these codes for a client, our function picks another code from that range to represent the original one
Despite we need to use those codes sequentially we are only sending the random values for the clients so it looks random from his perspective
When we receive this code back the from the client we're able to tell the original code
We would also be able to change the way that these codes are "shuffled", so different codes could be exposed over time while leaving the original ones untouched on our side


Sorry if I wasn't clear enough or destroyed math notations forever.
The subject is called format-preserving encryption,

and your last bullet point is addressed by tweaks.

Simple
http://web.cs.ucdavis.edu/~rogaway/papers/feistel.pdf

http://arxiv.org/pdf/1208.1176.pdf

http://web.cs.ucdavis.edu/~rogaway/papers/sr.html
Complex