本文实例讲述了 Python 生成密码库功能。分享给大家供大家参考,具体如下:
这个代码是将字符的所有组合添加到一个文件中,可以设置密码的最大长度,我这里设置的是 8 位,但是要有心里准备,生成的文件特别大。。。
- lshuai < ---~--->bc bc 1.06.95 Copyright 1991 - 1994,
- 1997,
- 1998,
- 2000,
- 2004,
- 2006 Free Software Foundation,
- Inc.This is free software with ABSOLUTELY NO WARRANTY.For details type`warranty '.
- (95*2+95^2*3+95^3*4+95^4*5+95^5*6+95^6*7+95^7*8+95^8*9)/1024/1024/1024
- 56132395
- '
下面是 python 的代码:
- #!/usr/bin/python
- import string
- letters = string.letters + string.digits + string.punctuation
- length = len(letters)
- fwrite = open("/tmp/genpass.txt","wt")
- fread = open("/tmp/genpass.txt","r")
- for num in xrange(8):
- for times in xrange(length**num):
- line=fread.read(num+1).rstrip()
- for letter in letters:
- fwrite.write(line + letter + "\n")
- fwrite.flush()
- fwrite.close()
- fread.close()
PS:这里再为大家提供两款相关在线工具供大家参考使用:
在线随机数字 / 字符串生成工具:http://tools.jb51.net/aideddesign/suijishu
高强度密码生成器:http://tools.jb51.net/password/CreateStrongPassword
更多关于 Python 相关内容感兴趣的读者可查看本站专题:《Python 数据结构与算法教程》、《Python Socket 编程技巧总结》、《Python 函数使用技巧总结》、《Python 字符串操作技巧汇总》、《Python 入门与进阶经典教程》及《Python 文件与目录操作技巧汇总》
希望本文所述对大家 Python 程序设计有所帮助。
来源: http://www.92to.com/bangong/2017/05-25/22238353.html