#importNS_ASSUME_NONNULL_BEGIN @interface HKXORManager: NSObject + (HKXORManager *)shareManager; /** * Calculate the XOR value * @param string The string that needs to be XORed * @return Get the string after XOR */ -(NSString *)stringXOR:(NSString *)string; @end NS_ASSUME_NONNULL_END
#import "HKXORManager.h"
@implementation HKXORManager
+ (HKXORManager *)shareManager {
static HKXORManager *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[HKXORManager alloc] init];
});
return instance;
}
- (NSString *)stringXOR:(NSString *)string {
if (string.length%2) {
string = [NSString stringWithFormat:@"0%@", string span>];
}
NSString *code = @"00";
for (int i=0; i<string.length; i=i+ 2) {
NSString *subString = [string substringWithRange:NSMakeRange(i, 2< /span>)];
code = [self pinxCreator:code withPinv:subString];
}
return code;
}
- (NSString *)pinxCreator:(NSString *)pan withPinv:(NSString *)pinv {
if (pan.length != pinv.length) {
return nil;
}
const char *panchar = [pan UTF8String];
const char *pinvchar = [pinv UTF8String];
NSString *temp = [[NSString alloc] init];
for (int i = 0; i) { int panValue = [self charToint:panchar[i]];
int pinvValue = [self charToint:pinvchar[i]];
temp = [temp stringByAppendingString:[NSString stringWithFormat:@"%X ",panValue^pinvValue]];
}
return temp;
}
- (int)charToint:(char)tempChar {
if (tempChar >= '0' && tempChar <='9') {
return tempChar-'0';
}
else if (tempChar >= 'A' && tempChar < = 'F' span>) {
return tempChar-'A' + 10;
}
return 0;
}
@end
#importNS_ASSUME_NONNULL_BEGIN @interface HKXORManager: NSObject + (HKXORManager *)shareManager; /** * Calculate the XOR value * @param string The string that needs to be XORed * @return Get the string after XOR */ -(NSString *)stringXOR:(NSString *)string; @end NS_ASSUME_NONNULL_END
#import "< span style="color: #800000;">HKXORManager.h"
@implementation HKXORManager
+ (HKXORManager *)shareManager {
static HKXORManager *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[HKXORManager alloc] init];
});
return instance;
}
- (NSString *)stringXOR:(NSString *)string {
if (string.length%2) {
string = [NSString stringWithFormat:@"0%@", string span>];
}
NSString *code = @"00";
for (int i=0; i<string.length; i=i+ 2) {
NSString *subString = [string substringWithRange:NSMakeRange(i, 2< /span>)];
code = [self pinxCreator:code withPinv:subString];
}
return code;
}
- (NSString *)pinxCreator:(NSString *)pan withPinv:(NSString *)pinv {
if (pan.length != pinv.length) {
return nil;
}
const char *panchar = [pan UTF8String];
const char *pinvchar = [pinv UTF8String];
NSString *temp = [[NSString alloc] init];
for (int i = 0; i) { int panValue = [self charToint:panchar[i]];
int pinvValue = [self charToint:pinvchar[i]];
temp = [temp stringByAppendingString:[NSString stringWithFormat:@"%X ",panValue^pinvValue]];
}
return temp;
}
- (int)charToint:(char)tempChar {
if (tempChar >= '0' && tempChar <='9') {
return tempChar-'0';
}
else if (tempChar >= 'A' && tempChar < = 'F' span>) {
return tempChar-'A' + 10;
}
return 0;
}
@end