-
Notifications
You must be signed in to change notification settings - Fork 83
/
main.m
45 lines (32 loc) · 1018 Bytes
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// 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 {
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++) {
unichar c = [input characterAtIndex:i];
c ^= key[i % (sizeof(key)/sizeof(unichar))];
[output appendString:[NSString stringWithFormat:@"%C", c]];
}
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;
}