shardic
New member
I need to convert the following C code to VB such that the resulting bit configurations are identical. Note that I cannot alter the variable types.
Being relatively new to VB I am a little confused concerning XOR'in VB ints with chars. Any advice is greatly appreciated.
char *somefunc( char *instr, char *pwstr, long len )
{
int j, pwlen, passnum;
long i;
char buff[1];
pwlen = strlen( pwstr ); /* length of password */
/* get seed value */
passnum = (int) ((((_tr_pnum(pwstr)/997) - 1) % 254 ) + 1);
for ( i = j = 0; i < len; i++ ) /* process whole string */
{
passnum = (int) (((passnum + ( i - len )) - 1 ) % 254) + 1;
buff[0] = (instr ^ (passnum ^ pwstr[j]) ); /* XOR 3 var's */
instr = (buff[0] ? buff[0] : instr); /* if NULL retrn char */
j = ( j >= pwlen ? 0 : j++ ); /* password que control variable */
}
return(instr); /* send back encrypted string */
}
Being relatively new to VB I am a little confused concerning XOR'in VB ints with chars. Any advice is greatly appreciated.
char *somefunc( char *instr, char *pwstr, long len )
{
int j, pwlen, passnum;
long i;
char buff[1];
pwlen = strlen( pwstr ); /* length of password */
/* get seed value */
passnum = (int) ((((_tr_pnum(pwstr)/997) - 1) % 254 ) + 1);
for ( i = j = 0; i < len; i++ ) /* process whole string */
{
passnum = (int) (((passnum + ( i - len )) - 1 ) % 254) + 1;
buff[0] = (instr ^ (passnum ^ pwstr[j]) ); /* XOR 3 var's */
instr = (buff[0] ? buff[0] : instr); /* if NULL retrn char */
j = ( j >= pwlen ? 0 : j++ ); /* password que control variable */
}
return(instr); /* send back encrypted string */
}