使用1-1函数生成的ID code [英] Generate code from id using a 1-1 function

查看:134
本文介绍了使用1-1函数生成的ID code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么好的可逆1-1函数整数映射到另一个整数? 对于例如,给出的范围0-5,我想找到一个映射:

Is there any good invertible 1-1 function that maps an integer to another integer? for eg, given the range 0-5, I want to find one that maps:

0->3
1->2
2->4
3->5
4->1
5->0

此外,映射看起来应该是随机的。

Also, the mapping should look random.

推荐答案

您可以填写升序排列数组,将它洗。这通常将执行相当不错,如果不是最有效的memorywise。

You can fill an array in ascending order and shuffle it. This will usually perform reasonably well, if not being the most efficient memorywise.

您也可以依靠一个封闭的独立变换,如乘法。如果你有2个号码,磷,钾,然后(我认为)只要磷,钾是互质,P ^ N模k,便会产生一种不重复的,长度值的伪随机序列(K - 1),从1到K.离散数学的这种特殊的表现形式是加密的premises之一。从序列倒退到指数是被称为离散对数问题,是传统RSA的原因是安全的。

You can also rely on a closed discrete transformation, such as multiplication. If you have 2 numbers, P and K, then (I think) as long as P and K are coprime, P^n mod K will produce a nonrepeating, pseudorandom sequence of values of length (K - 1), ranging from 1 to K. This particular manifestation of discrete math is one of the premises of cryptography. Going backwards from sequence to exponent is known as the discrete logarithm problem and is the reason traditional RSA is secure.

您问了可逆算法。如果保留指数的跟踪,你可以由对^ N模k的为P ^(N-1)模k的没有太大的困难。你可以采取一些快捷方式到电源倒退到指数中不加密工作,因为算法的某些参数被故意丢弃,使之更难。

You asked for a reversible algorithm. If you keep track of the exponent, you can go from P^n mod K to P^(n-1) mod K without much difficulty. You can take a few shortcuts to go backwards from power to exponent that don't work in cryptography because certain parameters of the algorithm are intentionally discarded to make it harder.

这是说,如果你碰巧破解RSA通过解决你在做这个,而离散对数问题,一定要告诉我。

That said, if you happen to break RSA by solving the discrete log problem while you're working on this, be sure to let me know.

这篇关于使用1-1函数生成的ID code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆