Skip to content

Instantly share code, notes, and snippets.

@dbr
Created January 5, 2010 20:46
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 dbr/269701 to your computer and use it in GitHub Desktop.
Save dbr/269701 to your computer and use it in GitHub Desktop.
Approximate time to brute-force a password
"""Calculates how long a password might take to brute force
"""
def chunks(l, n):
for i in xrange(0, len(l), n):
yield l[i:i+n]
def human_readable_number(n):
return ",".join(list(chunks(str(n)[::-1],3)))[::-1]
def time(total, persecond):
ttlsec = total / float(persecond)
minutes = ttlsec/60.0
hours = minutes/60.0
days = hours/24.0
weeks = days/7.0
years = weeks/52
return int(round(years))
def main():
num_possible_characters = (26 + 26 + 12)
password_size = 20
hashes_per_second = 1000000
number_of_machines = 500
permus = num_possible_characters ** password_size
print human_readable_number(permus)
howlong = time(permus, hashes_per_second * number_of_machines)
print human_readable_number(howlong) + " years"
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment