<?
function padding($msg,$nb_chars)
{
$charset = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'); for($cpt=0;$cpt<$nb_chars;$cpt++)
{
$msg .= $charset[$rand];
}
return $msg;
}
function mac($msg)
{
$key = "7h3_1337_k3y";
$nonce = "5uc3m01";
$bloc_size = 64;
{
$msg = padding
($msg,$bloc_size-strlen($msg)); $mac = $msg;
}
else if(strlen($msg)==$bloc_size) {
$mac = $msg;
}
else if(strlen($msg)>$bloc_size) {
$mac = hash_hmac("sha512",$msg.$nonce,$key,true); }
return crypt($mac,'$6$rounds=5000$OhMyG05h!');
}
$test = "dededededededededededededededededededededededededededededededed";
$cpt = 0;
$bloc_size = 64;
while($cpt < 1)
{
$return1 = padding
($test,$bloc_size-strlen($test)); $return2 = padding
($test,$bloc_size-strlen($test));
$return_cry1 = crypt($return1,'$6$rounds=5000$OhMyG05h!'); $return_cry2 = crypt($return2,'$6$rounds=5000$OhMyG05h!');
if($return_cry2 == $return_cry1)
{
$cpt = 2;
print("OK\n");
print $return1;
print $return2;
}
print("nok\n");
}
?>
PD8KCiBmdW5jdGlvbiBwYWRkaW5nKCRtc2csJG5iX2NoYXJzKQoJewoJCSRjaGFyc2V0ID0gYXJyYXkoJ2EnLCdiJywnYycsJ2QnLCdlJywnZicsJ2cnLCdoJywnaScsJ2onLCdrJywnbCcsJ20nLCduJywnbycsJ3AnLCdxJywncicsJ3MnLCd0JywndScsJ3YnLCd3JywneCcsJ3knLCd6JywnQScsJ0InLCdDJywnRCcsJ0UnLCdGJywnRycsJ0gnLCdJJywnSicsJ0snLCdMJywnTScsJ04nLCdPJywnUCcsJ1EnLCdSJywnUycsJ1QnLCdVJywnVicsJ1cnLCdYJywnWScsJ1onLCcwJywnMScsJzInLCczJywnNCcsJzUnLCc2JywnNycsJzgnLC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PSBjcnlwdCgkcmV0dXJuMSwnJDYkcm91bmRzPTUwMDAkT2hNeUcwNWghJyk7CgkJJHJldHVybl9jcnkyID0gY3J5cHQoJHJldHVybjIsJyQ2JHJvdW5kcz01MDAwJE9oTXlHMDVoIScpOwoJCQoJCWlmKCRyZXR1cm5fY3J5MiA9PSAkcmV0dXJuX2NyeTEpCgkJCXsKCQkJJGNwdCA9IDI7CgkJCXByaW50KCJPS1xuIik7CgkJCXByaW50ICRyZXR1cm4xOwoJCQlwcmludCAkcmV0dXJuMjsKCQkJfQoJCQoJCXByaW50KCJub2tcbiIpOwoJfQoJCj8+Cg==
<?
function padding($msg,$nb_chars)
{
$charset = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9');
for($cpt=0;$cpt<$nb_chars;$cpt++)
{
$rand = rand(0,61);
$msg .= $charset[$rand];
}
return $msg;
}
function mac($msg)
{
$key = "7h3_1337_k3y";
$nonce = "5uc3m01";
$bloc_size = 64;
if(strlen($msg)<$bloc_size)
{
$msg = padding($msg,$bloc_size-strlen($msg));
$mac = $msg;
}
else if(strlen($msg)==$bloc_size)
{
$mac = $msg;
}
else if(strlen($msg)>$bloc_size)
{
$mac = hash_hmac("sha512",$msg.$nonce,$key,true);
}
return crypt($mac,'$6$rounds=5000$OhMyG05h!');
}
$test = "dededededededededededededededededededededededededededededededed";
$cpt = 0;
$bloc_size = 64;
while($cpt < 1)
{
$return1 = padding($test,$bloc_size-strlen($test));
$return2 = padding($test,$bloc_size-strlen($test));
$return_cry1 = crypt($return1,'$6$rounds=5000$OhMyG05h!');
$return_cry2 = crypt($return2,'$6$rounds=5000$OhMyG05h!');
if($return_cry2 == $return_cry1)
{
$cpt = 2;
print("OK\n");
print $return1;
print $return2;
}
print("nok\n");
}
?>