标签:
/**
* 字符串异或加密
*
* @param oldStr 被加密的字符串
* @param x 字符偏移量
*
* @return 加密后的字符串
*/
- (NSString *)getCharArrayUsingString:(NSString *)oldstr withCharOffset:(int)x
{
if (nil == oldstr || [@"" isEqualToString:oldstr]) {
return @"";
}
unichar *charArray = malloc(sizeof(unichar) * (oldstr.length + 1));
int nCount = (int)oldstr.length;
for(int i = 0; i < nCount; i++){
charArray[i] = [oldstr characterAtIndex:i] ^ x;
}
charArray[nCount] = ‘\0‘;
NSString *newStr = [NSString stringWithCharacters:charArray length:nCount];
free(charArray);
return newStr;
}
标签:
原文地址:http://www.cnblogs.com/liuguanlei/p/4611312.html