아래의 extable 은 각 고유 키를 넣어 주면 됩니다. ^^
byte[] extable = {0x1D, 0x1D, 0x1B, 0x3F} ;
byte[] _changeBuf = {0,0,0,0} ;
void Start() {
Debug.Log(intToXOR(1000));
int kTemp = intToXOR(1000);
Debug.Log(xorToINT(kTemp));
Debug.Log(intToXOR(10000));
kTemp = intToXOR(10000);
Debug.Log(xorToINT(kTemp));
}
private void IntToByte(int num, byte[] value)
{
value[0] = (byte)((num >> 24) ^ extable[0]);
value[1] = (byte)((num >> 16) ^ extable[1]);
value[2] = (byte)((num >> 8) ^ extable[2]);
value[3] = (byte)(num ^ extable[3]);
}
private int ByteToIntNon(byte[] value)
{
int retV = 0;
retV = (((value[0] & 0xFF)) << 24) |
(((value[1] & 0xFF)) << 16) |
(((value[2] & 0xFF)) << 8) |
((value[3] & 0xFF));
return retV;
}
private void IntToByteNon(int num, byte[] value)
{
value[0] = ((byte)(num >> 24));
value[1] = ((byte)(num >> 16));
value[2] = ((byte)(num >> 8));
value[3] = ((byte)(num));
}
private int ByteToInt(byte[] value)
{
int retV = 0;
retV = (((value[0] & 0xFF) ^ extable[0]) << 24) |
(((value[1] & 0xFF) ^ extable[1]) << 16) |
(((value[2] & 0xFF) ^ extable[2]) << 8) |
((value[3] & 0xFF) ^ extable[3]);
return retV;
}
public int intToXOR(int _value) {
IntToByte(_value,_changeBuf);
return ByteToIntNon(_changeBuf);
}
public int xorToINT(int _value) {
IntToByteNon(_value,_changeBuf);
return ByteToInt(_changeBuf);
}