Skip to content

Instantly share code, notes, and snippets.

@MindScriptAct
Last active August 29, 2015 14:13
Show Gist options
  • Save MindScriptAct/5013f1adf95dcc78f87d to your computer and use it in GitHub Desktop.
Save MindScriptAct/5013f1adf95dcc78f87d to your computer and use it in GitHub Desktop.
Int data, protected from simple memory editors.
package utils {
public class SecureInt {
private var _value:int;
private var tempVal:IntValueObject;
public function SecureInt(initValue:int = 0) {
this.value = initValue;
}
public function set value(value:int):void {
_value = value;
tempVal = new IntValueObject(value);
}
public function get value():int {
return tempVal.getValue();
}
}
}
class IntValueObject {
var data:int;
var isNegative:Boolean = false;
const shift:int = Math.random() * 30;
public function IntValueObject(value:int) {
if (value < 0) {
isNegative = true;
value *= -1;
}
data = rotateLeft(~value);
}
public function getValue():int {
return (isNegative ? -1 : 1) * ~rotateRight(data);
}
private function rotateLeft(value:uint):uint {
return (value << shift) | (value >>> (32 - shift));
}
private function rotateRight(value:uint):uint {
return (value >>> shift) | (value << (32 - shift));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment