Skip to content

Instantly share code, notes, and snippets.

@Lucent
Created December 9, 2018 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lucent/3b9c5a678101e0535c1dde49f5287353 to your computer and use it in GitHub Desktop.
Save Lucent/3b9c5a678101e0535c1dde49f5287353 to your computer and use it in GitHub Desktop.
Removing ambiguous characters is the same as never including them
<?php
$LENGTH = 4;
$SAMPLES = 100000;
$all = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$ambig = ["l","1","I","o","O","0"];
$unambig = str_replace($ambig, "", $all);
function generate_passwords($remove, $set, $length, $samples) {
global $ambig;
$numbers_yes = 0;
$numbers_no = 0;
for ($a = 0; $a < $samples; $a++) {
$password = "";
for ($c = 1; $c <= $length * 2; $c++)
$password .= $set[random_int(0, strlen($set)-1)];
if ($remove)
$password = str_replace($ambig, "", $password);
$password = substr($password, 0, $length);
// echo $password, "\n";
if (strpbrk($password, "0123456789") == TRUE)
$numbers_yes++;
else
$numbers_no++;
}
return $numbers_no / ($numbers_yes + $numbers_no);
}
echo "No numbers when ambiguous characters never included:\t", generate_passwords(FALSE, $unambig, 4, 10000), "\n";
echo "No numbers when ambiguous characters removed:\t", generate_passwords(TRUE, $all, 4, 10000), "\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment