首页 > 其他 > 详细

字符串异或加密

时间:2015-06-30 20:00:40      阅读:95      评论:0      收藏:0      [点我收藏+]

/**

 *  字符串异或加密

 *

 *  @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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!