0

如果它存在于代码中,我正在寻找以下内容(任何语言都可以,但最好是 c#):

a,b,limit,key : integers

0< a, b, < limit (fits in less than int32)

b = forth(a, limit, key)
a = back (b, limit, key)

我需要一些看起来有点随机的东西,(=)而且(xor)还不够好。

Now I looked into block ciphers and pseudorandom generators and like but it's always about encryption and security and speed and uses the whole size of the integer. I don't care about any of those. All I need is a bijection on the domain where average of forth(a+epsilon) >> b+epsilon

4

1 回答 1

0

像下面这样简单的东西有什么问题吗?

int Forth(int a, int limit, int key)
{
    return (limit - a) ^ key;
}

int Back(int b, int limit, int key)
{
    return limit - (b ^ key);
}

编辑:改编自这里(虽然不使用密钥 - 这是必要的吗?)

int Forth(int a)
{
    return ((0x00FF & a)<<8) + ((0xFF00 & a)>>8);
}

int Back(int b)
{
    return ((0x00FF & b)<<8) + ((0xFF00 & b)>>8);
}

注意Back()Forth()上面的功能相同......

于 2013-04-04T09:31:54.997 回答