Skip to content

Instantly share code, notes, and snippets.

@brendanberg
Created June 20, 2012 02:07
Show Gist options
  • Save brendanberg/2957751 to your computer and use it in GitHub Desktop.
Save brendanberg/2957751 to your computer and use it in GitHub Desktop.
Generates every valid password for an incredibly stupid authentication system
import itertools
# Finding every single terrible password
#
# (Password requirements from http://kottke.org/12/06/the-worlds-worst-password-requirements-list)
#
# Must be exactly 8 characters long
# Must contain at least one character from each of these sets:
# ['@', '#', '$'],
# ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
# ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
# 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B',
# 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
# 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
# Must not contain '@', #', or '$' in either the first or last position
# Must not contain adjacent duplicate characters
#
# Prints every valid password to STDOUT after a very long time
def hasIdenticalAdjacents(str):
for x in zip(str[:-1], str[1:]):
if x[0] == x[1]:
return True
return False
characters = '@#$0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
restricted = '@#$'
for x in itertools.product(characters, repeat=8):
if x[0] not in restricted and x[-1] not in restricted:
if not hasIdenticalAdjacents(x):
print x
# Analysis:
# ratio
# length valid / possible valid : possible
# ------ ------------------- ----------------
# 2 3782 / 4225 0.895
# 3 242234 / 274625 0.882
# 4 15502790 / 17850625 0.868
# 5 991359850 / 1160290625 0.854 (est)
# 6 63414165750 / 75418890625 0.841 (est)
# 7 4055346181250 / 4902227890625 0.827 (est)
# 8 259270153268750 / 318644812890625 0.814 (est)
#
# With approximately 260 trillion passwords, a file containing all passwords
# would take up 2.0725 petabytes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment