码迷,mamicode.com
首页 > 编程语言 > 详细

关于简单的加密和解密算法

时间:2017-07-19 11:57:11      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:start   article   ace   for   length   white   复杂   log   pre   

加密解密 最简单的就是简单的字符串连接和运算,可是直接对字符串操作比較麻烦,所以建议一般做法是先把string转换为byte数组后再进行简单的异或运算或者其它运算进行加密和解密,终于比对的都是string、


void Start()

    {
        string s = "sxasxasx时刻到那时小时额外2饿饿2221312312";
        string SS = Encode(s);
        Debug.Log(SS);
        string SSS = Decode(SS);
        Debug.Log(SSS);
        Debug.Log(SSS == s);


       
}
    public string Encode(string s)
    { 
        byte[] b=Encoding.UTF8.GetBytes(s);
        for (uint i = 0; i < b.Length; i++)
        {
            uint by = b[i];
            b[i] = (byte)(by ^ 2);//异或 也能够使用复杂的运算。0x3234
        }
        return Encoding.UTF8.GetString(b);
    }
    public string Decode(string s)
    {
        byte[] b = Encoding.UTF8.GetBytes(s);
        for (uint i = 0; i < b.Length; i++)
        {
            uint by = b[i];
            b[i] = (byte)(by ^ 2);//异或
        }
        return Encoding.UTF8.GetString(b);
    }

关于简单的加密和解密算法

标签:start   article   ace   for   length   white   复杂   log   pre   

原文地址:http://www.cnblogs.com/yangykaifa/p/7204542.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!