Skip to content

Instantly share code, notes, and snippets.

@kristapsk
Created December 8, 2016 00:08
Show Gist options
  • Save kristapsk/638e108c661c4c9e4ab079663b66e98c to your computer and use it in GitHub Desktop.
Save kristapsk/638e108c661c4c9e4ab079663b66e98c to your computer and use it in GitHub Desktop.
<?php
$algo = 'sha512';
$algo_iter = 100;
$rand = ord(openssl_random_pseudo_bytes(1));
$pass = 'password';
$salt = openssl_random_pseudo_bytes(16);
$salt_hex = bin2hex($salt);
$finished = false;
$val = hash($algo, hash($algo, $pass) . $salt);
for ($i = 0; $i <= 255; $i++) {
$val2 = hash($algo, $val . $i);
for ($j = 0; $j < $algo_iter; $j++) {
$val2 = hash($algo, $val2);
}
if (!$finished) {
echo "$salt_hex $val2\n";
}
if ($i == $rand) {
echo "End at $i\n";
$finished = true;
//exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment