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

时间:2014-05-15 14:48:41

标签: powershell

我有一个字节数组:

$bytes = [System.IO.File]::ReadAllBytes($myFile)

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

bytes[i] ^= 0x6A  // python-style

我试过

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

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

如何在powershell中完成?

谢谢!

1 个答案:

答案 0 :(得分:9)

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

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