字节数组的非线性操作
可能的重复:
查找字节对数
我正在实现 SAFER+ 算法,该算法使用 16 字节字节数组并执行操作在字节上。
第一阶段包括带有子密钥的 XOR 和 ADDITON 功能,这里没有任何问题可提及。
第二阶段是非线性层,它对字节值使用 POWER 和 LOGARITHMS,这里的问题是当我们取值的“以 45 为底”的对数时,结果是浮点双精度,并且应该传递该值到阶段 3 作为一个字节,以与阶段 1 相同的方式进行处理。
Possible Duplicate:
Finding Byte logarithm
I am implemeting the SAFER+ algorithm, this algorithm uses 16 bytes byte-array and performs the operations on Bytes.
The first phase includes XOR and ADDITON funciton with the Subkeys, no problems to mention here.
The second phase is the nonlinear layer which uses POWER and LOGARITHMS on the bytes' values, the problem here is when we take the log "to base 45" of the Value, the result is a floating point double, and this value should be passed to phase 3 as a byte to be handled in the same way of the phase one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个如下所示的幂表:
“log”值为 45exp % 257。您需要一个带有
modPow
函数的任意精度算术库(引发一个数的幂,以某个值为模)来构建此表。您可以看到“exp”128 的值是一种特殊情况,因为通常零的对数是未定义的。通过在“log”列中查找数字来计算该数字的对数;该行“exp”列中的值是对数。
以下是初始化的草图:
例如,使用此设置,log45(131) =
log[131]
= 63 和 4538 =exp[38]
= 59。Create an exponentiation table that looks like this:
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.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.
Here's a sketch of the initialization:
With this setup, for example, log45(131) =
log[131]
= 63, and 4538 =exp[38]
= 59.您可以使用 Linq 表达式执行此操作,如下所示
但这会截断双精度数,因为它必须这样做...
已编辑在查看 SAFER+ 后,它使用 Log45(0)=128 的约定避免数字溢出。
You can do this with a Linq expression as follows
But this will truncate the double, as it has to do...
Edited after looking at SAFER+, it uses the convention that Log45(0)=128 to avoid numeric overflow.