Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i execute this code:

VB
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)


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

VB
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?
Posted

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900