对称双射算法整数整数、对称、算法

2023-09-11 01:47:09 作者:一别两宽

我需要一个算法,可以做一个一对一的映射(即没有冲突)的32位有符号整数到另一个32位有符号整数。

I need an algorithm that can do a one-to-one mapping (ie. no collision) of a 32-bit signed integer onto another 32-bit signed integer.

我的真正关心的是足够的熵使得函数的输出看起来是随机的。基本上,我在寻找类似的异或加密的密码,但是可以产生更加随心所欲看的输出。安全不是我真正关心的,虽然平凡才是。

My real concern is enough entropy so that the output of the function appears to be random. Basically I am looking for a cipher similar to XOR Cipher but that can generate more arbitrary-looking outputs. Security is not my real concern, although obscurity is.

编辑澄清用途:

算法必须是对称的,这样我可以扭转操作没有一个密钥。 算法必须是双射,每32位输入号码必须生成一个32位的唯一编号。 的函数的输出必须是足够晦涩,只有一个添加到输入应导致对输出大的效果。 The algorithm must be symetric, so that I can reverse the operation without a keypair. The algorithm must be bijective, every 32-bit input number must generate a 32-bit unique number. The output of the function must be obscure enough, adding only one to the input should result big effect on the output.

实例预期的结果: F(100)= 98456 F(101)= -758 F(102)= 10875498 F(103)= 986541 F(104)= 945451245 F(105)= -488554

Example expected result: F(100) = 98456 F(101) = -758 F(102) = 10875498 F(103) = 986541 F(104) = 945451245 F(105) = -488554

就像MD5,改变一件事情可能会改变很多东西。

Just like MD5, changing one thing may change lots of things.

我要寻找一个mathmetical功能,所以手动映射整数不是我一个解决方案。对于那些谁是问,算法速度不是很重要的。

I am looking for a mathmetical function, so manually mapping integers is not a solution for me. For those who are asking, algorithm speed is not very important.

推荐答案

使用任何32位块密码!根据定义,分组密码在其范围内的所有可能的输入值映射到一个独特的产值,在一个可逆的方式,并通过设计,就很难确定哪些任何给定的值映射到没有钥匙。只需选择一个关键,保持它的秘密,如果安全或默默无闻是重要的,使用的密码为您的转换。

Use any 32-bit block cipher! By definition, a block cipher maps every possible input value in its range to a unique output value, in a reversible fashion, and by design, it's difficult to determine what any given value will map to without the key. Simply pick a key, keep it secret if security or obscurity is important, and use the cipher as your transformation.

有关这个主意非幂的2范围的扩展,看到我在Secure置换与分组密码。

For an extension of this idea to non-power-of-2 ranges, see my post on Secure Permutations with Block Ciphers.

解决您的具体问题:

在该算法确实是对称的。我不知道你所说的扭转操作没有一个密钥的意思。如果你不想使用密钥,硬盘codea的随机生成的一个,并认为它是算法的一部分。 是的 - 根据定义,一个分组密码是双射。 是啊。这不会是一个很好的密码如果不是这样的话。