-
-
Save anonymous/6f2bc815e93f54d31257b5bf4a478c01 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 encode_password($plain, $challenge, $secret) { | |
if ((strlen($challenge) % 2) != 0 || | |
strlen($challenge) == 0) | |
return FALSE; | |
$hexchall = hex2bin($challenge); | |
if ($hexchall === FALSE) | |
return FALSE; | |
if (strlen($secret) > 0) { | |
$crypt_secret = md5($hexchall . $secret, TRUE); | |
$len_secret = 16; | |
} else { | |
$crypt_secret = $hexchall; | |
$len_secret = strlen($hexchall); | |
} | |
/* simulate C style \0 terminated string */ | |
$plain .= "\x00"; | |
$crypted = ''; | |
for ($i = 0; $i < strlen($plain); $i++) | |
$crypted .= $plain[$i] ^ $crypt_secret[$i % $len_secret]; | |
$extra_bytes = 0;//rand(0, 16); | |
for ($i = 0; $i < $extra_bytes; $i++) | |
$crypted .= chr(rand(0, 255)); | |
return bin2hex($crypted); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment