Skip to content

Instantly share code, notes, and snippets.

@lietu
Created May 11, 2016 13:50
Show Gist options
  • Save lietu/01a1bd6e221ce3793340dea46fd11dce to your computer and use it in GitHub Desktop.
Save lietu/01a1bd6e221ce3793340dea46fd11dce to your computer and use it in GitHub Desktop.
Python script to calculate minimum length of a key to achieve a given level of security.
#
# Calculate required key/password length to achieve satisfactory level
# of security. E.g. if you want something to be pretty secure so it can
# handle a week of brute forcing by pretty big hash farms.
#
# License: WTFPL http://www.wtfpl.net/
#
# How long do you want the cracking to take
TARGET_DURATION = 60 * 60 * 24 * 3 # Seconds
UPPER = 26 # Uppercase characters in the English alphabet
LOWER = 26 # Lowercase characters in the English alphabet
DIGITS = 10 # Digits 0-9
SYMBOLS = len("!@#$%&/(){}[]=+-,.") # What symbols you want to use
SEARCH_SPACE_DEPTH = UPPER + LOWER + DIGITS + SYMBOLS
GUESSES_PER_SECOND = 100000000000 # 100 billion
def space_duration(length, depth, persec):
space = depth ** length
duration = space / persec
return space, duration
def seconds_to_readable(seconds):
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
return "{}d {}h {}m {}s".format(days, hours, minutes, seconds)
if __name__ == "__main__":
print("Your search space depth is {} characters".format(
SEARCH_SPACE_DEPTH
))
print("You assume {:,} guesses per second".format(GUESSES_PER_SECOND))
characters = 0
space, duration = 0, 0
while duration < TARGET_DURATION:
characters += 1
space, duration = space_duration(characters, SEARCH_SPACE_DEPTH,
GUESSES_PER_SECOND)
print("Your target length is >= {} characters".format(
characters
))
print(
"You will achieve {:,} search space size, and it will take {} to bruteforce".format(
space,
seconds_to_readable(duration)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment