加密单个int的方法 [英] Way to encrypt a single int

查看:171
本文介绍了加密单个int的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何廉价地双向加密一个32位的int,这样每个数字都映射到这个空间的其他一些int并且以难以预测的方式返回?

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?

而且不需要在映射表中预先存储429亿个ints。

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

推荐答案

你想要什么是一个32位块密码。不幸的是,由于短块大小的弱点,大多数块密码都是64位或更多/ A>。如果可以处理加密的int是输入的两倍,那么可以使用Blowfish,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位,不介意安全性降低,那么它很容易修剪像Blowfish这样的Feistel网络密码,这个密码长度是2和小于启动密码。对于 Blowfish ,只需在两个半块之间平均分割输入数字,并修剪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.

这篇关于加密单个int的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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