- array_push: documentation ( source)
- implode: documentation ( source)
- random_int: documentation ( source)
<?php
/**
* Usage: Run this from the command line to generate a secure passphrase in the format
* of stereotypical bottom keymashing.
*
* php bottom-responder.php | xclip
*
* Why? Because furries ruin everything, including bottom jokes.
*/
function random_str(int $length, string $charset): string {
$c = strlen($charset) - 1;
if ($c < 1) {
throw new RangeException("Dumb");
}
$pieces = [];
for ($i = 0; $i < $length; ++$i) {
$x = random_int(0, $c);
array_push($pieces, $charset[$x]);
}
return implode($pieces);
}
/*
8 home row characters + 8 to 12 random letters + 4 home row characters
Entropy estimates
Lower end: 26.575 + 38.864 + 13.288 -> 78 bits
Upper end: 26.575 + 58.296 + 13.288 -> 98 bits
*/
$x = random_int(8, 12);
echo random_str(8, 'asdfghjkl;') . random_str($x, 'qwertyuiopasdfghjkl;zxcvbnm,.') . random_str(8, 'asdfghjkl;');