im trying to create lightweight value obscurer, against possibility to blatantly change primitive values in memory editor. Such as cheat engine. Here's what i have to far.
/// <summary>
/// Obscure for type int.
/// </summary>
public class ObscuredInt{
public ObscuredInt() {
this.value = 0;
}
public ObscuredInt(int value) {
this.value = value;
}
private int _a;
private int _b;
/// <summary>
/// Current obscure value.
/// </summary>
public int value {
get {
return _a + _b;
}
set {
_a = Random.Range(int.MinValue, int.MaxValue);
_b = value - _a;
}
}
}
usage
ObscuredInt health = new ObscuredInt(5);
health.value = 10;
printInConsle(health.value);
This works by simply never storing actual value, but rather a combination of two integers, which sum represents the value. That way the value is actually never cached long time in the memory. So finding it in a primitive way using cheat engine is not possible.
My question
I've seen other examples of obscuring, which involve conversion to binary or string hashing or other quite heavy operations.
This example is of course much more lightweight, how is this example worse than more advanced hashing or conversions. What flaws do you see with this example? What can you suggest?
Thank you