I'm having some troubles with xor operator.
I have a visual basic application that has a function whit this line:
numeroCaracter = Asc(password.Substring(contador, 1)) Xor Asc(CadenaEncriptacion.Substring(contador, 1))
password is a string that is received by the function, and CadenaEncriptacion is this constant:
Private Const CadenaEncriptacion As String = "eNcRiPtAcIoNmUyChUlAyGuAyDeLpArAgUaYeNcRiPtAcIoNmUyChUlAyGuAyDeLpArAgUaYeNcRiPtAcIoNmUyChUlAyGuAyDeLpArAgUaYeNcRiPtAcIoNmUyChUlAyGuAyDeLpArAgUaY"
I need translate the function to PHP, I traslated that line on this way:
$numeroCaracter = ord(substr($password, $contador, 1)) xor ord(substr($CadenaEncriptacion, $contador, 1));
The ord function in PHP and Asc in vb are giving the same values in both languages, but numeroCaracter has diferent value in PHP and VB, by the XOR operator...
In php numeroCaracer is always the ord value to each character, in vb the asc function give me other value.
Thanks!
As in php xor has lower precedence than = your code is interpreted like:
($numeroCaracter = ord(substr($password, $contador, 1))) xor ord(substr($CadenaEncriptacion, $contador, 1));
So, $numeroCaracter gets value of ord(substr($password, $contador, 1)). Add parentheses or use ^ operator instead of xor:
$numeroCaracter = ord(substr($password, $contador, 1)) ^ ord(substr($CadenaEncriptacion, $contador, 1));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With