zoukankan      html  css  js  c++  java
  • 字符串异或加密

    /**

     *  字符串异或加密

     *

     *  @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] = '';

        

        NSString *newStr = [NSString stringWithCharacters:charArray length:nCount];

        

        free(charArray);

        

        return newStr;

    }

  • 相关阅读:
    # 类和模板小结
    # Clion复制提示信息
    # IDEA相关知识
    # MySQL 笔记
    # MATLAB笔记
    # Mac地址
    # 丢包&&掉帧&&文件删除
    HDU 5744 Keep On Movin
    POJ 1852 Ants
    HDU 2795 Billboard
  • 原文地址:https://www.cnblogs.com/liuguanlei/p/4611312.html
Copyright © 2011-2022 走看看