密码学经常使用主要领域, http://mathworld.wolfram.com/FiniteField.html在这种情况下,GF(257)。看起来像这样:
exp | log
----+----
0 | 1
1 | 45
2 | 226
3 | 147
... | ...
128 | 0
... | ...
255 | 40
---------
The "log" values are 45exp % 257. You'll need an arbitrary precision arithmetic library with a modPow
function (raise a number to a power, modulo some value) to build this table. You can see that the value for "exp" 128 is a special case, since normally the logarithm of zero is undefined.
通过在“log”列中查找数字来计算该数字的对数;该行“exp”列中的值是对数。
这是初始化的草图:
BigInteger V45 = new BigInteger(45);
BigInteger V257 = new BigInteger(257);
byte[] exp = new byte[256];
for (int idx = 0; idx < 256; ++idx)
exp[idx] = BigInteger.ModPow(V45, new BigInteger(idx), V257) % 256;
byte[] log = new byte[256];
for (int idx = 0; idx < 256; ++idx)
log[exp[idx]] = idx;
With this setup, for example, log45(131) = log[131]
= 63, and 4538 = exp[38]
= 59.
(我从来没有写过 C#;我只是从BigInteger http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx文档;数据类型可能有错误。)