本文介绍了我如何计算在密码学对数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对字节进行非线性函数来实现SAFER +。该算法需要在字节计算基础-45对数,我不知道该怎么做。

I am trying to perform non-linear functions on bytes to implement SAFER+. The algorithm requires computing base-45 logarithm on bytes, and I don't understand how to do it.

登录 45 (201)= 1.39316393

log(201) = 1.39316393

当我分配给字节,值被截断为1,且无法恢复的确切的结果。

When I assign this to a byte, the value is truncated to 1, and I can't recover the exact result.

我应该怎么来处理这个

推荐答案

加密经常使用的在这种情况下,GF(257)。的这样的:

Cryptography often uses prime fields, in this case, GF(257). Create an exponentiation table that looks like this:


exp | log
----+----
  0 |   1
  1 |  45
  2 | 226
  3 | 147
... | ...
128 |   0
... | ...
255 |  40
---------



日志值45 % 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.

通过找到它计算一个数的对数在日志栏目;在该行的EXP列中的值的对数。

Compute the logarithm of a number by finding the it in the "log" column; the value in the "exp" column of that row is the logarithm.

下面是初始化的草图:

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;

通过这种设置,例如,日志(131)= 日志[131] = 63,和45 = EXP [38] = 59。

With this setup, for example, log(131) = log[131] = 63, and 45 = exp[38] = 59.

(我从来没有写C#;我只是从的文档;也有可能是与数据类型的错误)

(I've never written C#; I'm just guessing from the BigInteger documentation; there are likely to be errors with the data types.)

这篇关于我如何计算在密码学对数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-13 01:18