Skip to content

Instantly share code, notes, and snippets.

@foxwoods
Created March 22, 2012 17:19
Show Gist options
  • Save foxwoods/2160130 to your computer and use it in GitHub Desktop.
Save foxwoods/2160130 to your computer and use it in GitHub Desktop.
ASDF encoder
<?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