mirror of
https://github.com/KyleBanks/XOREncryption.git
synced 2023-08-10 21:13:15 +03:00
Added Objective-C implementationg
This commit is contained in:
parent
50cdacb50d
commit
aa702ca4c7
45
Objective-C/main.m
Normal file
45
Objective-C/main.m
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
//
|
||||||
|
// 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 {
|
||||||
|
char key[] = {'K', 'C', 'Q'};
|
||||||
|
NSMutableString *output = [[NSMutableString alloc] init];
|
||||||
|
|
||||||
|
for(int i = 0; i < input.length; i++) {
|
||||||
|
char c = [input characterAtIndex:i];
|
||||||
|
c ^= key[i % sizeof(key)/sizeof(char)];
|
||||||
|
[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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user