Created
December 9, 2018 08:03
-
-
Save Lucent/3b9c5a678101e0535c1dde49f5287353 to your computer and use it in GitHub Desktop.
Removing ambiguous characters is the same as never including them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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