Created
January 5, 2010 20:46
-
-
Save dbr/269701 to your computer and use it in GitHub Desktop.
Approximate time to brute-force a password
This file contains hidden or 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
"""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