Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created April 13, 2016 15:22
Show Gist options
  • Save anonymous/6f2bc815e93f54d31257b5bf4a478c01 to your computer and use it in GitHub Desktop.
Save anonymous/6f2bc815e93f54d31257b5bf4a478c01 to your computer and use it in GitHub Desktop.
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