cloudflare email 邮箱混淆/加密/解密 PHP 源码

yufei       4 年, 11 月 前       1225

在某个网站上看到一串 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;
}
目前尚无回复
简单教程 = 简单教程,简单编程
简单教程 是一个关于技术和学习的地方
现在注册
已注册用户请 登入
关于   |   FAQ   |   我们的愿景   |   广告投放   |  博客

  简单教程,简单编程 - IT 入门首选站

Copyright © 2013-2022 简单教程 twle.cn All Rights Reserved.