Skip to content

Instantly share code, notes, and snippets.

@anhldbk
Created March 19, 2017 11:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anhldbk/1d99f4926dde3bda3d6a263d2801b416 to your computer and use it in GitHub Desktop.
Save anhldbk/1d99f4926dde3bda3d6a263d2801b416 to your computer and use it in GitHub Desktop.
Password generator
# Write a password generator that meets these four criteria:
# 1- The password length is always 4
# 2- The password should consist letters and numbers from {A-F}, {a-f} and {1-6} and pick at least one from each of these(randomly)
# 3- No duplicate passwords generated
# 4- The password is generated totally randomly
array = list('ABCDEFabcdef123456')
count = 0
def print_passwd(passwd):
global count
count += 1
print passwd
def generate(chars):
mapping = {}
for char in chars:
mapping[char] = 0
string = ''
for key in mapping.keys():
if mapping[key] == 0:
string += key
mapping[key] = 1
if len(string) == len(mapping):
print_passwd(string)
gen(mapping, string)
mapping[key] = 0
string = string[:-1]
for i in xrange(0, 6):
for j in xrange(6, 12):
for k in xrange(12, 18):
for l in xrange(0, 18):
if l != i and l != j and l != k:
chars = [array[i], array[j], array[k], array[l] ]
generate(chars)
print 'Total passwords generated is %s' % count
@NehaSharma-11
Copy link

what does the below line do?
gen(mapping, string)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment