@
workaholic <?php
$a = encode(2147483642);
echo $a, '<br/>';
$b = decode($a);
echo $b;
function encode($id) {
if($id > 100) {
$id = (string) $id;
$len = strlen($id) - 1;
$id = $id{0} . $id{$len} . substr($id, 2, -1). $id{1};
}
$id += 60512868;
$str = base_convert($id, 10, 36);
$str = substr($str, 0, -2) . xchange($str{4}) . xchange($str{5});
return $str;
}
function decode($str) {
$str = substr($str, 0, -2) . xchange($str{4}, 1) . xchange($str{5}, 1);
$id = base_convert($str, 36, 10);
$id -= 60512868;
if($id > 100) {
$id = (string) $id;
$len = strlen($id) - 1;
return $id{0} . $id{$len} . substr($id, 2, -1). $id{1};
} else {
return $id;
}
}
function xchange($s, $decode = 0) {
if($decode) {
$str = "ytuvsrqzxwilng7fed2cbajk1096h53m8o4p";
} else {
$str = "poiuytrewqlkjhgfdsamnbvcxz6541239807";
}
$s = base_convert($s, 36, 10);
return $str{$s};
}
?>