flash.moe/public/key.php

27 lines
810 B
PHP
Raw Normal View History

2020-08-20 00:02:37 +00:00
<?php
2021-07-07 01:13:50 +00:00
define('KEY_CHARS', 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789');
define('KEY_CHARS_LENGTH', strlen(KEY_CHARS));
function generateKey(int $length): string {
2022-02-04 04:25:57 +00:00
$bytes = str_repeat("\0", $length);
2021-07-07 01:13:50 +00:00
for($i = 0; $i < $length; ++$i)
2022-02-04 04:25:57 +00:00
$bytes[$i] = KEY_CHARS[random_int(0, KEY_CHARS_LENGTH - 1)];
2021-07-07 01:13:50 +00:00
return $bytes;
}
2020-08-20 00:02:37 +00:00
header('Content-Type: text/plain');
2021-07-07 01:13:50 +00:00
if(isset($_GET['length'])) {
$length = (int)filter_input(INPUT_GET, 'length', FILTER_SANITIZE_NUMBER_INT);
if($length > 0 && $length < 1000) {
echo generateKey($length);
return;
}
}
2022-02-04 04:25:57 +00:00
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;