Arithmetic operation not returning in VB6 and C #

I translated the VB6 module containing a couple of encryption functions into C #. I have the following arrhythmic operation on both sides:

WITH#:

int inter, cfc;
inter = 6940;
cfc = Convert.ToInt32((((inter / 256) * 256) - (inter % 256)) / 256);
//cfc = 26

VB6:

Dim inter As long
Dim cfc As long     
inter = 6940
cfc = (((inter / 256) * 256) - (inter Mod 256)) / 256
'cfc = 27

I was not able to find out the inconsistency of the result, since all operations return integer numbers, this leads to an unexpected operation of the encryption process.

+4
source share
1 answer

In C # (inter / 256), integer division is performed, but VB6 is not. Thus, in one of your code samples, the result of this division is truncated to 27 before the rest of the operations, while the other uses the value 27.109375. This leads to a difference in your final results.

Use (inter \ 256)in VB6 if integer division is what you intend.

+9
source

Source: https://habr.com/ru/post/1689456/


All Articles