将XOR操作应用于字节数组?

Jer*_*emy 5 powershell

我有一个字节数组:

$bytes = [System.IO.File]::ReadAllBytes($myFile)
Run Code Online (Sandbox Code Playgroud)

我想对这个数组中的每个字节执行一个XOR运算,就像这样(在python中)

bytes[i] ^= 0x6A  // python-style
Run Code Online (Sandbox Code Playgroud)

我试过了

for($i=0; $i -lt $bytes.count ; $i++)
{
    $bytes[$i] = $bytes[$i] -xor 0x6A
}
Run Code Online (Sandbox Code Playgroud)

但是不起作用:$ bytes [$ i]的值是0x00.

怎么能在powershell中完成?

谢谢 !

Kei*_*ill 10

-xor是一个返回True或False的逻辑运算符.也许你想使用按位异或通过-bxor

for($i=0; $i -lt $bytes.count ; $i++)
{
    $bytes[$i] = $bytes[$i] -bxor 0x6A
}
Run Code Online (Sandbox Code Playgroud)