算术运算导致溢出。河豚algorythm [英] Arithmetic operation resulted in an overflow. blowfish algorythm

查看:124
本文介绍了算术运算导致溢出。河豚algorythm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行此代码时:



when i execute this code:

Dim bytearray() As Byte = System.IO.File.ReadAllBytes("C:\Users\Fery Ferdiansyah\Desktop\asd\asd.txt")
    Dim key() As Byte = System.Text.Encoding.UTF8.GetBytes("swagger")
    Dim bf As New blowfish2(key)





此语法>> y = S(0,a)+ S(1,b) <<在此函数中是算术溢出:





this syntax >> y = S(0, a) + S(1, b)<< in this function is arithmetic overflow:

Private Function F(ByVal x As UInteger) As UInteger
        Dim a As UShort
        Dim b As UShort
        Dim c As UShort
        Dim d As UShort
        Dim y As UInteger

        d = CUShort((x And &HFF))
        x >>= 8
        c = CUShort((x And &HFF))
        x >>= 8
        b = CUShort((x And &HFF))
        x >>= 8
        a = CUShort((x And &HFF))
        y = S(0, a) + S(1, b)
        y = y Xor S(2, c)
        y = y + S(3, d)

        Return y
    End Function





任何人都可以帮助我修复此函数?



could anyone help me to fix this function?

推荐答案

VB通常对它的数据类型是不可原谅的。我怀疑使用a和b的函数S存在铸造问题。 a和b是带有十六进制值的ANDing的结果,随后可以在S中返回否定结果。您将S的结果添加到无符号整数,并且两者不兼容。



您可以(但不要抱它)通过将UI添加到您的十六进制值来解决此问题:





VB in general is unforgiving with it's data types. I suspect that there is a casting problem with the function S with a and b. a and b are results of ANDing with a hex value, and subsequently could return a negative result in S. You're adding the results of S to an unsigned integer, and the two aren't compatible.

You might (but don't hold me to it) resolve this by appending UI to your hex values like this:


x And &HFFUI


这篇关于算术运算导致溢出。河豚algorythm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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