-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbyte_flipper.ps1
More file actions
20 lines (16 loc) · 840 Bytes
/
byte_flipper.ps1
File metadata and controls
20 lines (16 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Description:
# Iterates over every single byte inside the file and applys a bit mask to flip the last bit in the byte. Run it again to reverse the process.
$SourceFile = "./test.txt"
$beforeFileHash = (Get-FileHash $SourceFile).Hash
$SourceBytes = [System.IO.File]::ReadAllBytes($SourceFile)
Write-Host "Now flipping every 8th bit in" $SourceBytes.Length "bytes. Please wait..."
for($i=0; $i -lt $SourceBytes.count ; $i++)
{
# Apply a bit mask. 1 in Hex is Binary for 00000001. BXOR with that mask will flip the last bit in the byte.
$SourceBytes[$i] = $SourceBytes[$i] -bxor 1
}
Write-Host "Finished."
[System.IO.File]::WriteAllBytes($SourceFile , $SourceBytes)
Write-Host "File Hash Before: " $beforeFileHash
$afterFileHash = (Get-FileHash $SourceFile).Hash
Write-Host "File Hash After: " $afterFileHash