- (NSString *)QQJXPinxCreator:(NSString *)sha256
{
NSString * pan = [sha256 substringToIndex:sha256.length/2];
NSString * pinv = [sha256 substringFromIndex:sha256.length/2];
if (pan.length != pinv.length)
{
return @"生成的sha256字符串位数不是偶数!";
}
NSData * Data = [self convertHexStrToData:pan];
Byte * panByte = (Byte *)[Data bytes];
NSData * panData = [self convertHexStrToData:pinv];
Byte * pinvByte = (Byte *)[panData bytes];
Byte newData[Data.length];
for (int i = 0; i < Data.length; i++)
{
newData[i] = panByte[i]^pinvByte[i];
}
NSData * temdatas = [NSData dataWithBytes:newData length:Data.length];
NSString * temp = [self convertDataToHexStr:temdatas];
CXTLog(@"tyon = %@",temp);
return temp;
}
- (NSData*)convertHexStrToData:(NSString*)str
{
if (!str || [str length] ==0)
{
return nil;
}
NSMutableData *hexData = [[NSMutableData alloc]initWithCapacity:[str length]*2];
NSRange range;
if ([str length] %2==0)
{
range = NSMakeRange(0,2);
} else
{
range = NSMakeRange(0,1);
}
for (NSInteger i = range.location; i < [str length]; i +=2)
{
unsigned int anInt;
NSString *hexCharStr = [str substringWithRange:range];
NSScanner *scanner = [[NSScanner alloc]initWithString:hexCharStr];
[scanner scanHexInt:&anInt];
NSData *entity = [[NSData alloc]initWithBytes:&anInt length:1];
[hexData appendData:entity];
range.location+= range.length;
range.length=2;
}
return hexData;
}
- (NSString*)convertDataToHexStr:(NSData*)data
{
if (!data || [data length] ==0)
{
return @"";
}
NSMutableString *string = [[NSMutableString alloc]initWithCapacity:[data length]/2];
[data enumerateByteRangesUsingBlock:^(const void*bytes,NSRange byteRange,BOOL*stop)
{
unsigned char *dataBytes = (unsigned char*)bytes;
for (NSInteger i =0; i < byteRange.length; i++)
{
NSString *hexStr = [NSString stringWithFormat:@"%x", (dataBytes[i]) & 0xff];
if ([hexStr length] ==2)
{
[string appendString:hexStr];
} else
{
[string appendFormat:@"0%@", hexStr];
}
}
}];
return string;
}