在某个网站上看到一串 email 的混淆字符串,搜了一下,竟然是 cloudflare 家的。
这种方式感觉不错,因此,特意奉上 PHP 版本的混淆/还原代码
混淆
private function encodeEmail($email, $key=0) { $chars = str_split($email); $string = ''; $key = $key ? $key : rand(10, 99); foreach ($chars as $value) { $string .= sprintf("%02s", dechex(ord($value)^$key)); } return dechex($key).$string; }
还原
private function decodeEmail($encode) { $k = hexdec(substr($encode,0,2)); for($i=2, $m=''; $i < strlen($encode) - 1; $i += 2){ $m.=chr(hexdec(substr($encode, $i, 2))^$k); } return $m; }
目前尚无回复