Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply XOR operation to an array of bytes?

Tags:

powershell

I have an array of bytes :

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

I would like to perform a XOR operation on each 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 does not work : $bytes[$i] value is 0x00.

How can this be done in powershell ?

Thank you !

like image 618
Jeremy Avatar asked May 15 '14 14:05

Jeremy


1 Answers

-xor is a logical operator returning True or False. Perhaps you want to use bitwise exclusive OR'ing via -bxor?

for($i=0; $i -lt $bytes.count ; $i++)
{
    $bytes[$i] = $bytes[$i] -bxor 0x6A
}
like image 162
Keith Hill Avatar answered Sep 19 '22 11:09

Keith Hill