mangle.php
<?php
/*
** Spam HoneyTrap 1.0
**
** Produce a fake 12 letter address for spam harvesters
** that reveals their IP and the date in a mangled form
** that can be decoded on your end.
*/
/* $mangleX arrays:
** Set some initial values that will be assigned to digits
** in the hex of the IP octets and the date digits. Just
** for shits, the letters are ordered by letter frequency
** in Charles Dicken's Tale of Two Cities - first 10 for
** numbers in date; last 16 for hex of the IP octets.
*/
$mangleDate = array (
'0'=>'e',
'1'=>'t',
'2'=>'a',
'3'=>'o',
'4'=>'n',
'5'=>'i',
'6'=>'h',
'7'=>'s',
'8'=>'r',
'9'=>'d');
$mangleIP = array(
'0'=>'l',
'1'=>'u',
'2'=>'m',
'3'=>'w',
'4'=>'c',
'5'=>'f',
'6'=>'g',
'7'=>'y',
'8'=>'p',
'9'=>'b',
'a'=>'v',
'b'=>'k',
'c'=>'q',
'd'=>'x',
'e'=>'j',
'f'=>'z');
$ip = $_SERVER['REMOTE_ADDR'];
$today = date(md);
function mangle($ip,$date) {
global $mangleIP,$mangleDate;
$splitIP=split("\.",$ip);
$count = count($splitIP);
for ($i=0; $i<$count; $i++) {
$hex = dechex($splitIP[$i]);
if (!(strlen($hex)==2)) {
$hex='0'.$hex; //make sure double digit hex
}
$mangled = $mangleIP[($hex{0})].$mangleIP[($hex{1})].$mangleDate[$date{$i}];
$email.=$mangled.$datePart;
$ipHexTwo = array_search($mangled{0},$mangleIP);
$ipHexTwo = array_search($mangled{1},$mangleIP);
$octet = $ipHexOne.$ipHexTwo;
}
return $email;
}
function unMangle($mangle) {
global $mangleIP,$mangleDate;
strtolower($mangle);
$count = strlen($mangle) / 3;
for ($i=0; $i<$count; $i++) {
$mangleChunk = substr($mangle,$i*3,3);
$ip1 = array_search($mangleChunk{0},$mangleIP);
$ip2 = array_search($mangleChunk{1},$mangleIP);
$date = array_search($mangleChunk{2},$mangleDate);
if (!($i == ($count-1))) {
$spamIP .= hexdec($ip1.$ip2).'.';
} else {
$spamIP .= hexdec($ip1.$ip2);
}
$spamDate .= $date;
}
$spamDate = substr($spamDate,0,2).'/'.substr($spamDate,2,2);
return array($spamIP,$spamDate);
}
// Example usage:
$harvesterEmail = mangle($ip,$today);
list($harvesterIP,$harvesterDate) = unMangle($harvesterEmail);
?>
