<?php
// sample "passwords" to crypt
$pass = array('asdf', 'password', 'monkeyButt2014', 'G_QhU%&KRQRO9F8x+Z!VB+0w<^:67:*Rs8rW~w72\'IhU8g#|zl,e<cCW\'M,z%jN');
$salt = substr(str_replace('+', '.', base64_encode(pack('N4', mt_rand(), mt_rand(), mt_rand(), mt_rand()))), 0, 22);
$maxtime = 0;
define('MAXTIME', 30.0);

if (!CRYPT_BLOWFISH) {
	echo "Your PHP doesn't support Blowfish\n";
	echo phpversion() . ' ' . PHP_OS;
	exit();
}

$c = count($pass);
if ($c > 99) {
	die('Script should not be ran with more than 99 passwords');
}
$f = fopen('log.txt', 'wb');
fwrite($f, 'WL ');
echo 'WL ';
for($i = 1; $i <= $c; $i++) {
	fwrite($f, 'Pass ' . str_pad($i, 2, ' ', STR_PAD_LEFT) . '   ');
	echo 'Pass ' . str_pad($i, 2, ' ', STR_PAD_LEFT) . '   ';
}
fwrite($f, "\n== ");
echo "\n== ";
for($i = 1; $i <= $c; $i++) {
	fwrite($f, '========= ');
	echo '========= ';
}
for($l = 0; $l < 99; $l++) {
	$s = '$2a$' . str_pad($l, 2, '0', STR_PAD_LEFT) . '$' . $salt;
	fwrite($f, "\n" . str_pad($l, 2, '0', STR_PAD_LEFT) . ' ');
	echo "\n" . str_pad($l, 2, '0', STR_PAD_LEFT) . ' ';
	foreach($pass as $p) {
		$start = microtime(true);
		crypt($p, $s);
		$end = microtime(true);
		$t = $end - $start;
		$maxtime = max($maxtime, $t);
		fwrite($f, sprintf("%08.5F ", microtime(true) - $start));
		printf("%09.5F ", microtime(true) - $start);

	}
	if ($maxtime > MAXTIME) break;
}
fwrite($f, "\n");
echo "\n";
fclose($f);
?>
