Last active
August 29, 2015 13:58
-
-
Save mattypiper/10295093 to your computer and use it in GitHub Desktop.
obfuscates a file using 1-byte xor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void xorFile(string inputFilename, string outputFilename, byte xorValue) | |
{ | |
const int CHUNK_SIZE = 4096; | |
using (FileStream inputStream = new FileStream(inputFilename, FileMode.Open, FileAccess.Read)) | |
{ | |
BinaryReader binaryReader = new BinaryReader(inputStream, Encoding.ASCII); | |
using (FileStream outputStream = new FileStream(outputFilename, FileMode.Create, FileAccess.Write)) | |
{ | |
BinaryWriter binaryWriter = new BinaryWriter(outputStream, Encoding.ASCII); | |
byte[] chunk = binaryReader.ReadBytes(CHUNK_SIZE); | |
while (chunk.Length > 0) | |
{ | |
for (int i = 0; i < chunk.Length; i++) | |
{ | |
chunk[i] ^= xorValue; | |
} | |
binaryWriter.Write(chunk); | |
chunk = binaryReader.ReadBytes(CHUNK_SIZE); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment