flash.moe/public/key.php
2022-02-04 04:25:57 +00:00

26 lines
810 B
PHP

<?php
define('KEY_CHARS', 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789');
define('KEY_CHARS_LENGTH', strlen(KEY_CHARS));
function generateKey(int $length): string {
$bytes = str_repeat("\0", $length);
for($i = 0; $i < $length; ++$i)
$bytes[$i] = KEY_CHARS[random_int(0, KEY_CHARS_LENGTH - 1)];
return $bytes;
}
header('Content-Type: text/plain');
if(isset($_GET['length'])) {
$length = (int)filter_input(INPUT_GET, 'length', FILTER_SANITIZE_NUMBER_INT);
if($length > 0 && $length < 1000) {
echo generateKey($length);
return;
}
}
echo '8: ' . generateKey(8) . PHP_EOL;
echo '16: ' . generateKey(16) . PHP_EOL;
echo '32: ' . generateKey(32) . PHP_EOL;
echo '64: ' . generateKey(64) . PHP_EOL;
echo '128: ' . generateKey(128) . PHP_EOL;