1. 程式人生 > >關於簡單的加密和解密算法

關於簡單的加密和解密算法

sss 建議 ace class 算法 dsm length pac data

加密解密 最簡單的就是簡單的字符串連接和運算,可是直接對字符串操作比較麻煩,所以建議一般做法是先把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);
}

關於簡單的加密和解密算法