Apply XOR operation to byte array?

I have an array of bytes:

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

I would like to perform an XOR operation for every byte inside this array, like this (in python)

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

I tried

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

But it does not work: $ bytes [$ i] value is 0x00.

How can this be done in powershell?

Thank!

+4
source share
1 answer

-xoris a logical operator that returns True or False. Perhaps you want to use bitwise exclusive OR'ing through -bxor?

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

Source: https://habr.com/ru/post/1540721/


All Articles