路加密单个int路加、int

2023-09-10 22:56:35 作者:夜长梦多@

你怎么能便宜两路加密32位int,使得每个号码映射到在该领域的一些其他的int和背部的方式,很难predict?

How can you inexpensively two-way encrypt a 32 bit int, such that every number maps to some other int in that space and back in a way that's difficult to predict?

和不需要$ P $对存储当然4.29十亿个整数中的映射表,

And doesn't require pre-storing 4.29 billion ints in a mapping table, of course.

推荐答案

你想要的是一个32位的分组密码。不幸的是,大多数密码块是64位或更多,由于短块大小的弱点。如果你能处理的加密INT是两倍大的投入,那么你可以只用河豚,TDES,或其他一些很好的审核64位的分组密码。

What you want is a 32-bit block cipher. Unfortunately, most block ciphers are 64-bits or more due to the weaknesses of a short block size. If you can handle the encrypted int being twice as large as the input, then you can just use Blowfish, TDES, or some other nicely vetted 64-bit block cipher.

如果你真的需要32位,不介意降低安全那么它很容易修剪像河豚的Feistel网络密码到任何块长度是2和低于起始密码的倍数。对于河豚,只是分割你输入号码均匀两个半块之间,和装饰的输出F函数和P值下降为1/2目标块尺寸。这可以键控算法照常毕竟完成。

If you really need 32 bits and don't mind the decreased security then its easy enough to trim a Feistel network cipher like Blowfish down to any block length that's a multiple of 2 and less than the starting cipher. For Blowfish, just split your input number evenly between the two half blocks, and trim the output of the F function and the P-values down to 1/2 your target block size. This can all be done after keying the algorithm as usual.