Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Help deciphering powershell code

$
0
0

The section you highlighted ($b[$_],$b[$i] = $b[$i],$b[$_]) will swap two values in array $b: the one at index $_ with the one at index $i.

Also for reference if others are curious, this snippet comes from here: https://gist.github.com/AndrewSav/6102160. Just because it’s in a function to decrypt some data though doesn’t mean it has to be quite so cryptic. :)

Below is another version of the same script, expanded out a little. I haven’t tried it but I believe it will do the same thing.

for ($i = $j = 0; $i -lt 256; $i++) {

    # I didn’t figure out what keySeed and b were for, so I can’t really comment on this line
    $j += $b[$i] + $keySeed[$i]

    # Make sure $j is less than or equal to 255 (0xff) by stripping off the higher bits so that it continues to be a valid index into our array
    $j = $j -band 0xff

    # Swap $b[$i] with $b[$j]
    $b[$i],$b[$j] = $b[$j],$b[$i]
}

Viewing all articles
Browse latest Browse all 13067

Trending Articles