创建双射以获得具有已知最大值的无序计数器
我有一个具有已知最大值(称为 max
)的计数器。 max
可以很大(实际上它可以是 36^40 - 1
或 62^40 - 1
)。
我想要一个从 [0..max]
到 [0..max]
的双射 b
,具有以下属性: b( n+1)
不容易从 b(n)
猜出。
我不是寻找加密安全函数,我只是想要尽可能多的熵来混淆计数器的输出。
该函数必须可以在 PHP 中执行。这允许 PHP 执行的所有功能。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这个问题目前的形式是无法回答的。标准
定义不明确中猜出。您没有给出任何指标或可量化的约束。由于您继续写道您“不是搜索加密安全函数”,并在评论中提到您“并不真正关心任何人找到该函数”,因此不清楚为什么您需要双射根本。
但是,这里有一些想法可以帮助您找到满意的双射或澄清您的问题以便其他人可以提供帮助。
任何线性多项式可逆模
max
都可以。也就是说,以下形式的多项式给出双射当且仅当
最简单的情况是
a=1
和b=0
,因此b(n) = n
,这似乎满足您模糊的限制。如果您想喜欢它,您可以经常更改
a
和b
,比如生成一个随机数(但一定要检查gcd(a ,max) = 1
否则你不会得到双射)。I do not think this question is answerable in it's current form. The criterion
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 formgives a bijection if and only if
The easiest case is
a=1
andb=0
, so thatb(n) = n
, which seems to satisfy your vague constraints.If you want to get fancy with it, you could change
a
andb
often, say be generating a random number (but be sure to check thatgcd(a,max) = 1
or you will not get a bijection).