Skip to content

Commit aa702ca

Browse files
author
KyleBanks
committed
Added Objective-C implementationg
1 parent 50cdacb commit aa702ca

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Objective-C/main.m

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+

0 commit comments

Comments
 (0)