Skip to content

Instantly share code, notes, and snippets.

@diederikh
Created May 17, 2014 15:11
Show Gist options
  • Save diederikh/94d879f1b4e802d0cf56 to your computer and use it in GitHub Desktop.
Save diederikh/94d879f1b4e802d0cf56 to your computer and use it in GitHub Desktop.
Obfuscate data
// Fill this out with whatever you want. Use the same string
// and algorithm to scramble the files on the server.
static unsigned char secretString[SECRET_STRING_LENGTH];
- (NSData *)scrambleOrDescrambleData:(NSData*)input
{
unsigned char *outputBytes = malloc(input.length);
memcpy(outputBytes, input.bytes, input.length);
for (int i = 0; i < input.length; i++)
{
outputBytes[i] = outputBytes[i] ^ secretString[i % SECRET_STRING_LENGTH];
}
NSData *outputData = [[NSData alloc] initWithBytes:outputBytes length:input.length];
free(outputBytes);
return outputData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment