Created
March 22, 2012 17:19
-
-
Save foxwoods/2160130 to your computer and use it in GitHub Desktop.
ASDF encoder
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
<?php | |
class ASDF{ | |
private static $r = 10000000; | |
private static $d = 10001; | |
private static $f = 0; | |
public static function encode($x) { | |
$x %= (self::$r - self::$r % self::$d); | |
return floor(self::$r / self::$d) * (($x + self::$f) % self::$d) + floor($x / self::$d); | |
} | |
public static function decode($y) { | |
$m = floor(self::$r / self::$d); | |
return (floor($y / $m)+(self::$d - self::$f % self::$d)) % self::$d + ($y % $m) * self::$d; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment