Created
November 24, 2016 03:41
-
-
Save symbolic/7a7208308fe59edb6734a219ca6f0aad to your computer and use it in GitHub Desktop.
产生密码字典
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
Python生成黑客字典,首先需要字符串来源 | |
可以使用string包中的printable,具体作用如下: | |
string.printable为所有字符的集合,包含数字,大小写字母,符号包含空格制表符回车等; | |
使用string.printable[:-9]可获得: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~这些符号,因为一般的字典中不会用到空格回车等这些特殊字符,因此只需要前面的字符即可。 | |
要获得数字所组成的字符串集合,即为:string.printable[:10] | |
要获得字母所组成的字符串集合,即为:string.printable[10:62] | |
生成字符串通过迭代组合即可以得到所需的字典内容,然后存储下来就可以得到所谓的黑客字典。 | |
迭代过程使用itertools,这部分内容,详情可以自行百度或者Google。 | |
使用方法:python *.py 6 6 Six_nums_dict.txt | |
其中第一个参数为最短长度,第二个参数为最长长度,第三个参数为存储路径(存储文件) | |
这样就生成了单个字符长为6的字典,打开Six_nums_dict.txt,即可看到生成信息; | |
因为一般密码长度不会太长,所以没有必要生成太长的密码, | |
参数说明: | |
例如: # dict.py 3 6 password.txt | |
3:最短密码 | |
6:最长密码 | |
password.txt 的保存文件名 | |
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
#!/usr/bin/env python | |
#coding:utf-8 | |
#By eathings | |
# Create the dictionary from aaa to zzz | |
# argv[1] min-length | |
# argv[2] max-length | |
# argv[3] file name | |
import sys | |
import string | |
import itertools | |
def get_strings(): | |
chars=string.printable[10:36] | |
strings=[] | |
for i in xrange(min,max+1): | |
strings.append((itertools.product(chars,repeat=i),)) | |
return itertools.chain(*strings) | |
def make_dict(): | |
f = open(file,'a') | |
for x in list_str: | |
for y in x: | |
f.write("".join(y)) | |
f.write('\n') | |
f.close() | |
print 'Done' | |
while True: | |
if len(sys.argv)==4: | |
try: | |
min = int(sys.argv[1]) | |
max = int(sys.argv[2]) | |
except: | |
print "wrong" | |
sys.exit(0) | |
if min <= max: | |
list_str= get_strings() | |
file=sys.argv[3] | |
make_dict() | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment