为了防止游戏过程中被第三方应用搜索到真实数据信息,我们需要对基础数据类型进行二次封装并加密。
基本思想就是设置一个密码,然后与真实数据进行异或操作。
为了使用方便,可以对运算符进行重载,这样就可以像使用基本数据类型一样使用了。
直接上代码:
public struct AHInt
{
private static int cryptoKey = 123456;
private int currentCryptoKey;
private int hiddenValue;
public int v
{
get { return InternalEncryptDecrypt(); }
set { currentCryptoKey = cryptoKey; hiddenValue = EncryptDecrypt(value); }
}
public AHInt(int value)
{
currentCryptoKey = cryptoKey;
hiddenValue = EncryptDecrypt(value);
}
public static void SetNewCryptoKey(int newKey)
{
cryptoKey = newKey;
}
public int GetEncrypted()
{
if (currentCryptoKey != cryptoKey)
{
hiddenValue = InternalEncryptDecrypt();
hiddenValue = EncryptDecrypt(hiddenValue, cryptoKey);
curre