问题
I want a math function y = f(x) where x and y are 32 bit integers, such that
- it is reversible by some function x = g(y)
- the sequence f(1), f(2), f(3), ... looks random
I thought about XOR with some constant key, but that fails to look random. Also I could use DES or AES. But those seem like overkill.
Is there something simpler?
回答1:
Try a block cipher such as Skip32. But note that this does always encrypt one value to another value, so you need to remember that repetition of the input leads to repetition of the output, possibly leaking information to the adversary.
Otherwise you can have a look at format preserving encryption. There are ways of halving the size of a block cipher such as 3DES, which has a significantly higher security margin (112 bits if you use three random keys), e.g. using a Feistel Network.
A weird cipher is the Hasty Pudding Cipher, which has a configurable block size. However, the security of that cipher is questionable and not researched enough at the very minimum.
回答2:
After asking this question, I found a different solution (appending a hash to my sequential key). But it's still an interesting question. And I think the best answer is to implement a simple block cipher algorithm. There are several examples here.
来源:https://stackoverflow.com/questions/54973990/reversible-math-function-that-looks-random