Skip to content

Instantly share code, notes, and snippets.

@MindScriptAct
Created January 9, 2015 14:46
Show Gist options
  • Save MindScriptAct/d4fe9e9022f6ff777a7d to your computer and use it in GitHub Desktop.
Save MindScriptAct/d4fe9e9022f6ff777a7d to your computer and use it in GitHub Desktop.
Uint data, protected from simple memory editors.
package utils {
public class SecureUint {
private var _value:uint;
private var tempVal:UintValueObject;
public function SecureUint(initValue:uint = 0) {
this.value = initValue;
}
public function set value(value:uint):void {
_value = value;
tempVal = new UintValueObject(value);
}
public function get value():uint {
return tempVal.getValue();
}
}
}
class UintValueObject {
private var data:uint;
private const shift:uint = Math.random() * 30;
public function UintValueObject(value:uint) {
data = rotateLeft(~value);
}
public function getValue():uint {
return ~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