I have a counter with a known maximum (called max
). max
can be big (actually it will be either 36^40 - 1
or 62^40 - 1
).
I want a bijection b
from [0..max]
to [0..max]
with the following property: b(n+1)
not easily guessable from b(n)
.
I am NOT searching for a cryptographically secure function, I just want as much entropy as possible to obfuscate a little the output of a counter.
The function must be doable in PHP. This allows all the functions PHP does.
I do not think this question is answerable in it's current form. The criterion
b(n+1)
is not easily guessable fromb(n)
is not well-defined. You have given no metric or quantifiable constraint. Since you go on to write that you are "NOT searching for a cryptographically secure function" and mention in the comments that you "do not truly care that anyone find the function", it is unclear why you need the bijection at all.
However, here are some ideas that may help you either find a bijection you're happy with or clarify your question so others can help.
Any linear polynomial invertible modulo max
will work. That is, a polynomial of the form
b(n) = a*n + b mod max
gives a bijection if and only if
gcd(a,max) = 1
The easiest case is a=1
and b=0
, so that b(n) = n
, which seems to satisfy your vague constraints.
If you want to get fancy with it, you could change a
and b
often, say be generating a random number (but be sure to check that gcd(a,max) = 1
or you will not get a bijection).