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

加密解密 最简单的就是简单的字符串连接和运算,可是直接对字符串操作比較麻烦,所以建议一般做法是先把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);
    }
posted @ 2017-07-19 10:52  yangykaifa  阅读(238)  评论(0编辑  收藏  举报