Skip to content

Instantly share code, notes, and snippets.

@mattypiper
Last active August 29, 2015 13:58
Show Gist options
  • Save mattypiper/10295093 to your computer and use it in GitHub Desktop.
Save mattypiper/10295093 to your computer and use it in GitHub Desktop.
obfuscates a file using 1-byte xor
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