algorithm is now able to process unichar (two byte) characters such as Chinese or Cyrillic

This commit is contained in:
dautermann 2015-09-03 03:54:30 -04:00
parent 21f282e08a
commit c01da94345
1 changed files with 4 additions and 4 deletions

View File

@ -14,13 +14,13 @@
@implementation XOREncryption
+(NSString *) encryptDecrypt:(NSString *)input {
char key[] = {'K', 'C', 'Q'}; //Can be any chars, and any size array
unichar key[] = {'K', 'C', 'Q'}; //Can be any chars, and any size array
NSMutableString *output = [[NSMutableString alloc] init];
for(int i = 0; i < input.length; i++) {
char c = [input characterAtIndex:i];
c ^= key[i % sizeof(key)/sizeof(char)];
[output appendString:[NSString stringWithFormat:@"%c", c]];
unichar c = [input characterAtIndex:i];
c ^= key[i % sizeof(key)/sizeof(unichar)];
[output appendString:[NSString stringWithFormat:@"%C", c]];
}
return output;