迭代可能的密码时无限循环

时间:2018-02-24 16:48:13

标签: c cs50

我写了一个公认的丑陋程序,用暴力破解最多5个字母字符的密码,这个字符由基于DES的crypt()函数进行哈希处理,但是在运行时程序会导致无限循环。我无法确定原因。有谁看到我哪里出错了?我只是问无限循环,虽然我当然很欣赏有关嵌套for循环方法的替代方案的建议。

from business_duration import businessDuration
import pandas as pd
from datetime import time,datetime
import holidays as pyholidays

startdate = pd.to_datetime('2017-01-01 00:00:00')
enddate = pd.to_datetime('2017-01-31 23:00:00')

starttime=time(9,0,0)
endtime=time(17,0,0)

holidaylist = pyholidays.Australia()
unit='hour'

#By default weekends are Saturday and Sunday
print(businessDuration(startdate,enddate,starttime,endtime,holidaylist=holidayli
st,unit=unit))

Output: 160.0

holidaylist:
{datetime.date(2017, 1, 1): "New Year's Day",
 datetime.date(2017, 1, 2): "New Year's Day (Observed)",
 datetime.date(2017, 1, 26): 'Australia Day',
 datetime.date(2017, 3, 6): 'Canberra Day',
 datetime.date(2017, 4, 14): 'Good Friday',
 datetime.date(2017, 4, 15): 'Easter Saturday',
 datetime.date(2017, 4, 17): 'Easter Monday',
 datetime.date(2017, 4, 25): 'Anzac Day',
 datetime.date(2017, 6, 12): "Queen's Birthday",
 datetime.date(2017, 9, 26): 'Family & Community Day',
 datetime.date(2017, 10, 2): 'Labour Day',
 datetime.date(2017, 12, 25): 'Christmas Day',
 datetime.date(2017, 12, 26): 'Boxing Day'}

2 个答案:

答案 0 :(得分:3)

代码终止的唯一方法是,如果<{1}}中{em}} password_found = check_password(possible_password, hash);上次调用返回1。

添加5个地方

for (int n = 0; n < 52; n++)

...或

在5个地方

password_found = check_password(possible_password, hash);
// Add some means to exit the nested loops
if (password_found) return 0;

并删除

 //       v--- j,k,l,m,n
 for (int x = 0; password_found == 0 && x < 52; x++)

答案 1 :(得分:1)

while(password_founds == 0)表示如果您的程序找不到密码,它将保持无限循环。 比你有5个for循环,所有这些都修改var password_founds所以如果你想检查密码你必须跟踪更改。 我建议你将5个检查插入一个单独的独特功能中。