-
Notifications
You must be signed in to change notification settings - Fork 2
/
xor.ps1
27 lines (22 loc) · 1.6 KB
/
xor.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
param
([Parameter (Mandatory=$true)]
[string] $file1,
[Parameter (Mandatory=$true)]
[string] $file2,
[Parameter (Mandatory=$true)]
[string] $out
)#end param
#Read two files as byte arrays
$file1_b = [System.IO.File]::ReadAllBytes("$file1")
$file2_b = [System.IO.File]::ReadAllBytes("$file2")
#Set the length to be the smaller one
$len = if ($file1_b.Count -lt $file2_b.Count){$file1_b.Count}
else{$xord_byte_array = New-Object Byte[] $len}
#XOR between the files
for ($i=0; $i -lt $len; $i++)
{$xord_byte_array[$i] = $file1_b[$1] -bxor $file2_b[$i]
#Write the XORd bytes to the output file
[System.IO.File]::WriteAllBytes("$out", $xord_byte_array)
write-host"[*] $file1 XOR $file2'n[*] Saved to " -nonewline;
write-host"$out" -foregroundcolor yellow -nonewline;
write-host ".";