python 窮舉指定長度的密碼例子
本程序可根據(jù)給定的字符字典,窮舉指定長度的所有字符串:
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
結(jié)果:
aaaaabaacabaabbabcacaacbaccbaababbacbbabbbbbcbcabcbbcccaacabcaccbacbbcbcccaccbccc
本程序占用內(nèi)存小,生成速度快,歡迎嘗試!!!
補(bǔ)充知識(shí):Python 窮舉法, 二分法 與牛頓-拉夫遜方法求解平方根的性能對(duì)比
窮舉法, 二分法 與牛頓-拉夫遜方法求解平方根的優(yōu)劣,從左到右依次遞優(yōu)。
經(jīng)過測試,窮舉法基本超過 1 分鐘,還沒有出數(shù)據(jù);
二分法只要區(qū)區(qū)1秒不到就出結(jié)果了。
牛頓-拉夫遜是秒出,沒有任何的停頓。
numberTarget =int(input('Please enter a number:'))numberSqureRoot = 0while(numberSqureRoot<abs(numberTarget)): if numberSqureRoot**2 >= abs(numberTarget): break numberSqureRoot = numberSqureRoot + 1if 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 = 0lowValue = 0.0highValue=numberTarget*1.0epsilon = 0.01numberSqureRoot = (highValue + lowValue)/2while 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) /2print('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 = 0epsilon = 0.01k=numberTargetnumberSqureRoot = k/2.0while( abs(numberSqureRoot*numberSqureRoot - k)>=epsilon): numberSqureRoot=numberSqureRoot-(((numberSqureRoot**2) - k)/(2*numberSqureRoot))print('squre root of %s is %s ' %(numberTarget,numberSqureRoot))
以上這篇python 窮舉指定長度的密碼例子就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ajax請求添加自定義header參數(shù)代碼2. ASP基礎(chǔ)知識(shí)VBScript基本元素講解3. Python requests庫參數(shù)提交的注意事項(xiàng)總結(jié)4. IntelliJ IDEA導(dǎo)入jar包的方法5. Gitlab CI-CD自動(dòng)化部署SpringBoot項(xiàng)目的方法步驟6. Kotlin + Flow 實(shí)現(xiàn)Android 應(yīng)用初始化任務(wù)啟動(dòng)庫7. 利用CSS3新特性創(chuàng)建透明邊框三角8. python爬蟲學(xué)習(xí)筆記之pyquery模塊基本用法詳解9. ASP中解決“對(duì)象關(guān)閉時(shí),不允許操作。”的詭異問題……10. python操作mysql、excel、pdf的示例
