Python字典小脚本

时间:2022-03-11 00:16:59

http://zone.wooyun.org/content/20847


大概是这样的。两个字典。混合进去生成一个字典。列如字典1.txt的内容为xxx。字典2.txt的内容为123456 
要生成xxx123456或者123456xxx这样的字典


a =[]
for line in open('1.txt','r').readlines():
line = line.strip()
if len(line)>0: a.append(line)
b =[]
for line in open('2.txt','r').readlines():
line = line.strip()
if len(line)>0: b.append(line)
dy = {'0':a,'1':b}
wcd = 2
allpwd = []
def genfromstr(genedstr):
if len(genedstr) == 1 : return dy[genedstr[0]][:]
pwds = []
repwd = genfromstr(genedstr[1:])
allpwd.extend(repwd)
for pwd in repwd:
for opwd in dy[genedstr[0]]:
pwds.append(opwd+pwd)
return pwds


for i in range(0,1<<wcd):
genedstr = bin(i)[2:]
genedstr = '0'*(wcd-len(genedstr)) + genedstr
allpwd.extend(genfromstr(genedstr))

allpwd = list(set(allpwd))
print allpwd
output = open('3.txt', 'a+')
for p in allpwd:
output.write(p+'\n')
output.close()