xor 运算符在 PHP 和 Visual Basic 中的工作方式不同
xor operator working diferent in PHP and Visual Basic
我在使用 xor 运算符时遇到了一些问题。
我有一个 visual basic 应用程序,它具有以下行的功能:
numeroCaracter = Asc(password.Substring(contador, 1)) Xor Asc(CadenaEncriptacion.Substring(contador, 1))
password是函数接收的字符串,CadenaEncriptacion就是这个常量:
Private Const CadenaEncriptacion As String = "eNcRiPtAcIoNmUyChUlAyGuAyDeLpArAgUaYeNcRiPtAcIoNmUyChUlAyGuAyDeLpArAgUaYeNcRiPtAcIoNmUyChUlAyGuAyDeLpArAgUaYeNcRiPtAcIoNmUyChUlAyGuAyDeLpArAgUaY"
我需要将函数翻译成 PHP,我是这样翻译那行的:
$numeroCaracter = ord(substr($password, $contador, 1)) xor ord(substr($CadenaEncriptacion, $contador, 1));
PHP 中的 ord 函数和 vb 中的 Asc 在两种语言中给出相同的值,但 numeroCaracter 在 PHP 和 VB 中具有不同的值,通过异或运算符...
在 php 中,numeroCaracer 始终是每个字符的 ord 值,在 vb 中,asc 函数给我其他值。
谢谢!
如 php xor
的优先级 比 =
低 您的代码被解释喜欢:
($numeroCaracter = ord(substr($password, $contador, 1))) xor ord(substr($CadenaEncriptacion, $contador, 1));
因此,$numeroCaracter
获得了 ord(substr($password, $contador, 1))
的值。添加括号或使用 ^
运算符而不是 xor
:
$numeroCaracter = ord(substr($password, $contador, 1)) ^ ord(substr($CadenaEncriptacion, $contador, 1));
我在使用 xor 运算符时遇到了一些问题。
我有一个 visual basic 应用程序,它具有以下行的功能:
numeroCaracter = Asc(password.Substring(contador, 1)) Xor Asc(CadenaEncriptacion.Substring(contador, 1))
password是函数接收的字符串,CadenaEncriptacion就是这个常量:
Private Const CadenaEncriptacion As String = "eNcRiPtAcIoNmUyChUlAyGuAyDeLpArAgUaYeNcRiPtAcIoNmUyChUlAyGuAyDeLpArAgUaYeNcRiPtAcIoNmUyChUlAyGuAyDeLpArAgUaYeNcRiPtAcIoNmUyChUlAyGuAyDeLpArAgUaY"
我需要将函数翻译成 PHP,我是这样翻译那行的:
$numeroCaracter = ord(substr($password, $contador, 1)) xor ord(substr($CadenaEncriptacion, $contador, 1));
PHP 中的 ord 函数和 vb 中的 Asc 在两种语言中给出相同的值,但 numeroCaracter 在 PHP 和 VB 中具有不同的值,通过异或运算符...
在 php 中,numeroCaracer 始终是每个字符的 ord 值,在 vb 中,asc 函数给我其他值。
谢谢!
如 php xor
的优先级 比 =
低 您的代码被解释喜欢:
($numeroCaracter = ord(substr($password, $contador, 1))) xor ord(substr($CadenaEncriptacion, $contador, 1));
因此,$numeroCaracter
获得了 ord(substr($password, $contador, 1))
的值。添加括号或使用 ^
运算符而不是 xor
:
$numeroCaracter = ord(substr($password, $contador, 1)) ^ ord(substr($CadenaEncriptacion, $contador, 1));