python 穷举指定长度的密码例子


Posted in Python onApril 02, 2020

本程序可根据给定的字符字典,穷举指定长度的所有字符串:

def get_pwd(str, num):
  if(num == 1):
   for x in str:
    yield x
  else:
   for x in str:
    for y in get_pwd(str, num-1):
     yield x+y
 
strKey="abc"
for x in get_pwd(strKey,3):
 print x

结果:

aaa
aab
aac
aba
abb
abc
aca
acb
acc
baa
bab
bac
bba
bbb
bbc
bca
bcb
bcc
caa
cab
cac
cba
cbb
cbc
cca
ccb
ccc

本程序占用内存小,生成速度快,欢迎尝试!!!

补充知识:Python 穷举法, 二分法 与牛顿-拉夫逊方法求解平方根的性能对比

穷举法, 二分法 与牛顿-拉夫逊方法求解平方根的优劣,从左到右依次递优。

经过测试,穷举法基本超过 1 分钟,还没有出数据;

二分法只要区区1秒不到就出结果了。

牛顿-拉夫逊是秒出,没有任何的停顿。

numberTarget =int(input("Please enter a number:"))
numberSqureRoot = 0
while(numberSqureRoot<abs(numberTarget)):
 if numberSqureRoot**2 >= abs(numberTarget):
  break
 numberSqureRoot = numberSqureRoot + 1

if numberSqureRoot**2 != numberTarget:
 print("Your number %s is not a perfect squre, the square root is %s " % ( numberTarget,numberSqureRoot) )
else:
 if numberTarget < 0 :
  numberSqureRoot = -numberSqureRoot
 print("Your number %s is a perfect squre, the square root is %s " % ( numberTarget, numberSqureRoot))

print("now we begin to calculate the binary search...")

numberTarget=int(input("Please enter the number for binary search..."))
numberSqureRoot = 0

lowValue = 0.0
highValue=numberTarget*1.0

epsilon = 0.01
numberSqureRoot = (highValue + lowValue)/2

while abs(numberSqureRoot**2 - numberTarget) >=epsilon:
 print("lowValue:%s, highValue:%s, currentValue:%s"%(lowValue,highValue,numberSqureRoot))
 if numberSqureRoot**2<numberTarget:
  lowValue=numberSqureRoot
 else:
  highValue=numberSqureRoot
 numberSqureRoot = (lowValue+highValue) /2

print("The number %s has the squre root as %s " %(numberTarget,numberSqureRoot))


print("now we begin to calculate the newTon search...")

numberTarget=int(input("Please enter the number for newTon search..."))
numberSqureRoot = 0

epsilon = 0.01
k=numberTarget
numberSqureRoot = k/2.0

while( abs(numberSqureRoot*numberSqureRoot - k)>=epsilon):
 numberSqureRoot=numberSqureRoot-(((numberSqureRoot**2) - k)/(2*numberSqureRoot))

print("squre root of %s is %s " %(numberTarget,numberSqureRoot))

以上这篇python 穷举指定长度的密码例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python中的默认参数详解
Jun 24 Python
简单理解Python中的装饰器
Jul 31 Python
使用python实现生成用户信息
Mar 20 Python
fastcgi文件读取漏洞之python扫描脚本
Apr 23 Python
Python实现PS图像抽象画风效果的方法
Jan 23 Python
浅谈python下含中文字符串正则表达式的编码问题
Dec 07 Python
Python如何使用Gitlab API实现批量的合并分支
Nov 27 Python
python中提高pip install速度
Feb 14 Python
python能在浏览器能运行吗
Jun 17 Python
python批量修改交换机密码的示例
Sep 22 Python
pandas按条件筛选数据的实现
Feb 20 Python
Python使用mitmproxy工具监控手机 下载手机小视频
Apr 18 Python
python3安装OCR识别库tesserocr过程图解
Apr 02 #Python
python简单的三元一次方程求解实例
Apr 02 #Python
Python 线性回归分析以及评价指标详解
Apr 02 #Python
Django REST framwork的权限验证实例
Apr 02 #Python
详解Ubuntu环境下部署Django+uwsgi+nginx总结
Apr 02 #Python
在 Pycharm 安装使用black的方法详解
Apr 02 #Python
Python Numpy中数据的常用保存与读取方法
Apr 01 #Python
You might like
php将mysql数据库整库导出生成sql文件的具体实现
2014/01/08 PHP
php顺序查找和二分查找示例
2014/03/27 PHP
php微信公众平台开发(一) 配置接口
2016/12/06 PHP
PHP+MariaDB数据库操作基本技巧备忘总结
2018/05/21 PHP
Sample script that deletes a SQL Server database
2007/06/16 Javascript
在模板页面的js使用办法
2010/04/01 Javascript
JavaScript字符串对象charAt方法入门实例(用于取得指定位置的字符)
2014/10/17 Javascript
JavaScript中常用的六种互动方法示例
2015/03/13 Javascript
jQuery中值得注意的trigger方法浅析
2016/12/12 Javascript
js设置文字颜色的方法示例
2016/12/30 Javascript
jQuery使用unlock.js插件实现滑动解锁
2017/04/04 jQuery
基于bootstrap实现bootstrap中文网巨幕效果
2017/05/02 Javascript
ExtJs异步无法向外传值和赋值的完美解决办法
2017/06/14 Javascript
利用jQuery+localStorage实现一个简易的计时器示例代码
2017/12/25 jQuery
微信小程序block的使用教程
2018/04/01 Javascript
jquery拖拽自动排序插件使用方法详解
2020/07/20 jQuery
Weex开发之地图篇的具体使用
2019/10/16 Javascript
Javascript异步执行不按顺序解决方案
2020/04/30 Javascript
基于jquery实现彩色投票进度条代码解析
2020/08/26 jQuery
nodejs中的异步编程知识点详解
2021/01/17 NodeJs
Python3数据库操作包pymysql的操作方法
2018/07/16 Python
PyQt5实现简易计算器
2020/05/30 Python
Python字符串大小写转换拼接删除空白
2019/09/19 Python
css3实现3D文本悬停改变效果的示例代码
2019/01/16 HTML / CSS
迪拜领先运动补剂零售品牌中文站:Sporter商城
2019/08/20 全球购物
网络技术支持面试题
2013/04/22 面试题
忠诚教育心得体会
2014/09/03 职场文书
药店营业员岗位职责
2015/04/14 职场文书
学校捐书倡议书
2015/04/27 职场文书
色戒观后感
2015/06/12 职场文书
安全生产隐患排查制度
2015/08/05 职场文书
2016年“六一儿童节”校园广播稿
2015/12/17 职场文书
学校体育节班级口号
2015/12/25 职场文书
2019初中学生入团申请书
2019/06/27 职场文书
浅谈PostgreSQL表分区的三种方式
2021/06/29 PostgreSQL
Python 的 sum() Pythonic 的求和方法详细
2021/10/16 Python