$b32='0123456789abcdefghijklmnopqrstuv';
function generate_mailaddress($salt,$pepper)
{
global $b32;
global $_SERVER;
$t=time()>>2; // 29 bits until year 2038
$ip=$_SERVER['REMOTE_ADDR'];
$long = (ip2long($ip)+$salt)&0xffffffff;
if ($long === -1) {
return 'wrong';
} else {
srand($long+$t+$pepper);
$rand=rand(0,0x1ff);
$s='';
$x=$long; //32 bits
for($i=0;$i<6;$i++){$s=$b32[$x&0x1f].$s;$x>>=5;};
$x=$x&=0x3|$t<<2; //2+29=31 bits
for($i=0;$i<6;$i++){$s=$b32[$x&0x1f].$s;$x>>=5;};
$x=$x&0x1|$rand<<1; //1+9=10 bits
for($i=0;$i<2;$i++){$s=$b32[$x&0x1f].$s;$x>>=5;};
$x=23;
for($i=0;$i<14;$i++){
$x+=strpos($b32,$s[$i]);
if($x>31){$x-=32;};
$s[$i]=$b32[$x];
}
$c='.-_';
$x=rand(0,3);
for($i=0;$i<$x;$i++) {
$y=rand(1,13+$i);
$s=substr($s,0,$y).$c[rand(0,2)].substr($s,$y);
};
return $s;
}
}
function decode_mailaddress($mailaddress, $salt, $pepper)
{
global $b32;
$s=ereg_replace('[-._]','',$mailaddress);
$x=23;
for($i=0;$i<14;$i++){
$y=strpos($b32,$s[$i]);
$x=-$x+$y;
if($x<0){$x+=32;};
$s[$i]=$b32[$x];
$x=$y;
}
$x=0;
for($i=0;$i<2;$i++){$x=$x<<5|strpos($b32,$s[0]);$s=substr($s,1);};
$rnd2=$x>>1;
$x&=0x1;
for($i=0;$i<6;$i++){$x=$x<<5|strpos($b32,$s[0]);$s=substr($s,1);};
$time2=$x>>2;
for($i=0;$i<6;$i++){$x=$x<<5|strpos($b32,$s[0]);$s=substr($s,1);};
srand($x+$time2+$pepper);
if($rnd2-rand(0,0x1ff)) {
$s=invalid;
} else {
$s=sprintf('%s %s',long2ip(($x-$salt)&0xffffffff),
date("Y-m-d H:i:s",$time2<<2));
}
return $s;
}
$zweiundvierzig=12345678923;
$dreiundzwanzig=32165498742;
print generate_mailaddress($dreiundzwanzig,$zweiundvierzig)."@nowhere.invalid
";
print generate_mailaddress( 0,$zweiundvierzig) ."@nowhere.invalid
";
print generate_mailaddress( 0,0) ."@nowhere.invalid
";
$s=generate_mailaddress($dreiundzwanzig,$zweiundvierzig);
print(decode_mailaddress($s,$dreiundzwanzig,$zweiundvierzig).'
');
print(decode_mailaddress('x'.$s,$dreiundzwanzig,$zweiundvierzig));
?>