File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //
2+ // main.m
3+ // XOREncryption
4+ //
5+ // Created by Kyle Banks on 2013-10-06.
6+ //
7+
8+ #import < Foundation/Foundation.h>
9+
10+ @interface XOREncryption : NSObject
11+ +(NSString *) encryptDecrypt : (NSString *)input ;
12+ @end
13+
14+ @implementation XOREncryption
15+
16+ +(NSString *) encryptDecrypt : (NSString *)input {
17+ char key[] = {' K' , ' C' , ' Q' };
18+ NSMutableString *output = [[NSMutableString alloc ] init ];
19+
20+ for (int i = 0 ; i < input.length ; i++) {
21+ char c = [input characterAtIndex: i];
22+ c ^= key[i % sizeof (key)/sizeof (char )];
23+ [output appendString: [NSString stringWithFormat: @" %c " , c]];
24+ }
25+
26+ return output;
27+ }
28+
29+ @end
30+
31+
32+
33+ int main (int argc, const char * argv[])
34+ {
35+
36+ @autoreleasepool {
37+ NSString *encrypted = [XOREncryption encryptDecrypt: @" kylewbanks.com" ];
38+ NSLog (@" Encrypted:%@ " , encrypted);
39+
40+ NSString *decrypted = [XOREncryption encryptDecrypt: encrypted];
41+ NSLog (@" Decrypted:%@ " , decrypted);
42+ }
43+ return 0 ;
44+ }
45+
You can’t perform that action at this time.
0 commit comments