2013-10-06 23:41:44 +04:00
|
|
|
//
|
|
|
|
// main.m
|
|
|
|
// XOREncryption
|
|
|
|
//
|
|
|
|
// Created by Kyle Banks on 2013-10-06.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
|
|
|
@interface XOREncryption : NSObject
|
|
|
|
+(NSString *) encryptDecrypt:(NSString *)input;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation XOREncryption
|
|
|
|
|
|
|
|
+(NSString *) encryptDecrypt:(NSString *)input {
|
2015-09-03 10:54:30 +03:00
|
|
|
unichar key[] = {'K', 'C', 'Q'}; //Can be any chars, and any size array
|
2013-10-06 23:41:44 +04:00
|
|
|
NSMutableString *output = [[NSMutableString alloc] init];
|
|
|
|
|
|
|
|
for(int i = 0; i < input.length; i++) {
|
2015-09-03 10:54:30 +03:00
|
|
|
unichar c = [input characterAtIndex:i];
|
|
|
|
c ^= key[i % sizeof(key)/sizeof(unichar)];
|
|
|
|
[output appendString:[NSString stringWithFormat:@"%C", c]];
|
2013-10-06 23:41:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, const char * argv[])
|
|
|
|
{
|
|
|
|
|
|
|
|
@autoreleasepool {
|
|
|
|
NSString *encrypted = [XOREncryption encryptDecrypt:@"kylewbanks.com"];
|
|
|
|
NSLog(@"Encrypted:%@", encrypted);
|
|
|
|
|
|
|
|
NSString *decrypted = [XOREncryption encryptDecrypt:encrypted];
|
|
|
|
NSLog(@"Decrypted:%@", decrypted);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|