Created
September 16, 2010 21:06
-
-
Save alecgorge/583167 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function num_exchange ($int) { | |
$arr = array('W','x','J','y','5','v','l','0','R','M'); | |
return $arr[$int]; | |
} | |
function num_rev_exchange ($let) { | |
$arr = array('W','x','J','y','5','v','l','0','R','M'); | |
return array_search($let, $arr); | |
} | |
function rand_char_for_n ($n) { | |
while($c <= $n) { | |
$char .= trim(base64_encode(chr(rand(1,1500))), '=+/'); | |
$c = strlen($char); | |
} | |
return substr($char, 0, $n); | |
} | |
function encode_email ($email) { | |
$str = base64_encode(strrev(base64_encode($email))); | |
$stripped = rtrim($str, '='); | |
$rand_pos = rand(0, 9); | |
return strrev(num_exchange($rand_pos).substr($stripped, 0, $rand_pos).num_exchange((strlen($str) - strlen($stripped))).rand_char_for_n($rand_pos).substr($stripped, $rand_pos)); | |
} | |
function decode_email ($email) { | |
$email = strrev($email); | |
$pos_char = num_rev_exchange(substr($email, 0, 1)); | |
$num_char = num_rev_exchange(substr($email, 1 + $pos_char, 1)); | |
return base64_decode(strrev(base64_decode(substr($email, 1, $pos_char).substr($email, $pos_char+$pos_char+2).str_repeat('=', $num_char)))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment