mirror of
https://github.com/KyleBanks/XOREncryption.git
synced 2023-08-10 21:13:15 +03:00
algorithm is now able to process unichar (two byte) characters such as Chinese or Cyrillic
This commit is contained in:
parent
21f282e08a
commit
c01da94345
@ -14,13 +14,13 @@
|
|||||||
@implementation XOREncryption
|
@implementation XOREncryption
|
||||||
|
|
||||||
+(NSString *) encryptDecrypt:(NSString *)input {
|
+(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];
|
NSMutableString *output = [[NSMutableString alloc] init];
|
||||||
|
|
||||||
for(int i = 0; i < input.length; i++) {
|
for(int i = 0; i < input.length; i++) {
|
||||||
char c = [input characterAtIndex:i];
|
unichar c = [input characterAtIndex:i];
|
||||||
c ^= key[i % sizeof(key)/sizeof(char)];
|
c ^= key[i % sizeof(key)/sizeof(unichar)];
|
||||||
[output appendString:[NSString stringWithFormat:@"%c", c]];
|
[output appendString:[NSString stringWithFormat:@"%C", c]];
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
Loading…
Reference in New Issue
Block a user