Created
January 10, 2021 20:54
-
-
Save AdriDevelopsThings/84a21caa250d4df469b29d2b0c08e44d to your computer and use it in GitHub Desktop.
Get the optimal password length from charset.
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
from math import log | |
DEFAULT_CHARSET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!§$%&/()=?+*#-_.:,;<>" | |
Entropie = lambda p: - sum([i * log(i, 2) for i in p]) | |
charset = input(f"Charset [{DEFAULT_CHARSET}]: ") | |
if charset in (None, "", " "): | |
charset = DEFAULT_CHARSET | |
charset_length = len(charset) | |
p = 1 / charset_length | |
e = Entropie([p for i in range(charset_length)]) | |
print("Optimal password length:", int(100 / e) + 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment