Created
January 9, 2015 14:46
-
-
Save MindScriptAct/d4fe9e9022f6ff777a7d to your computer and use it in GitHub Desktop.
Uint data, protected from simple memory editors.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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