From c01da943459820e7053e14aa44efe4feeae637d7 Mon Sep 17 00:00:00 2001 From: dautermann Date: Thu, 3 Sep 2015 03:54:30 -0400 Subject: [PATCH] algorithm is now able to process unichar (two byte) characters such as Chinese or Cyrillic --- Objective-C/main.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Objective-C/main.m b/Objective-C/main.m index 83f9a61..40326b5 100644 --- a/Objective-C/main.m +++ b/Objective-C/main.m @@ -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;