我如何计算在密码学对数? [英] How do I compute logarithms in cryptography?

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

问题描述

我想对字节进行非线性函数来实现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

log45(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 EXP %257.你需要用 modPow 功能的高精度计算库(养数量的电力,模一定的价值)来构建这个表。你可以看到,对于值EXP128是一种特殊的情况下,由于通常的零的对数是不确定的。

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.

通过找到它计算一个数的对数在日志栏目;在该行的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;

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

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

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

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

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

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