手机版 欢迎访问it开发者社区(www.mfbz.cn)网站

当前位置: > 开发

Python预估破译密码所需时间

时间:2021/6/3 12:59:34|来源:|点击: 次

密码长度、组成不同时,破译密码需要的时间也不同
用python判断一下破解该密码需要多长时间

# # 判断破译密码所需要的时间,对着理论表格敲代码就行了。
import re
password = input()
length = len(password)
alpha = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'
num = '0123456789'
char = '~!@#$%^&*()_+{}|":?><`,./;[]\=-?\''
# # 最开始设置含有字母、数字、字符为False
contain_alpha = False
contain_num = False
contain_char = False

# # local = bool(re.findall(password, alpha))  # # 找到返回True,没找到返回False
# # print(local)

if length < 3 and length > 0:
    print('破译密码需要: 0.001秒')
elif length == 3:
    print('破译密码需要: 0.001秒')
elif length == 4:
    print('破译密码需要: 0.001秒')
elif length == 5:
    if password.isnumeric():
        print('破译密码需要: 0.001秒')
    if password.isalpha():
        print('破译密码需要: 0.001秒')
    else:
        # #  判断密码中的每一位,密码不长,时间复杂度可以接受,找到了设置相应的包含字母、数字、符号为True即可
        for i in password:
            if bool(re.findall(i, alpha)):
                contain_alpha = True
            if bool(re.findall(i, num)):
                contain_num = True
            if bool(re.findall(i, char)):
                contain_char = True
        if contain_alpha and contain_num and not contain_char:  # # 密码仅包含数字字母
            print('破译密码需要: 3秒')
        if contain_alpha and contain_num and contain_char:
            print('破译密码需要: 10秒')
elif length == 6:
    if password.isnumeric():
        print('破译密码需要: 0.001秒')
    if password.isalpha():
        print('破译密码需要: 8秒')
    else:
        for i in password:
            if bool(re.findall(i, alpha)):
                contain_alpha = True
            if bool(re.findall(i, num)):
                contain_num = True
            if bool(re.findall(i, char)):
                contain_char = True
        if contain_alpha and contain_num and not contain_char:  # # 密码仅包含数字字母
            print('破译密码需要: 3分钟')
        if contain_alpha and contain_num and contain_char:
            print('破译密码需要: 13分钟')
elif length == 7:
    if password.isnumeric():
        print('破译密码需要: 0.001秒')
    if password.isalpha():
        print('破译密码需要: 5分钟')
    else:
        for i in password:
            if bool(re.findall(i, alpha)):
                contain_alpha = True
            if bool(re.findall(i, num)):
                contain_num = True
            if bool(re.findall(i, char)):
                contain_char = True
        if contain_alpha and contain_num and not contain_char:  # # 密码仅包含数字字母
            print('破译密码需要: 3小时')
        if contain_alpha and contain_num and contain_char:
            print('破译密码需要: 17小时')
elif length == 8:
    if password.isnumeric():
        print('破译密码需要: 0.001秒')
    if password.isalpha():
        print('破译密码需要: 3小时')
    else:
        for i in password:
            if bool(re.findall(i, alpha)):
                contain_alpha = True
            if bool(re.findall(i, num)):
                contain_num = True
            if bool(re.findall(i, char)):
                contain_char = True
        if contain_alpha and contain_num and not contain_char:  # # 密码仅包含数字字母
            print('破译密码需要: 10天')
        if contain_alpha and contain_num and contain_char:
            print('破译密码需要: 57天')
elif length == 9:
    if password.isnumeric():
        print('破译密码需要: 4秒')
    if password.isalpha():
        print('破译密码需要: 4天')
    else:
        for i in password:
            if bool(re.findall(i, alpha)):
                contain_alpha = True
            if bool(re.findall(i, num)):
                contain_num = True
            if bool(re.findall(i, char)):
                contain_char = True
        if contain_alpha and contain_num and not contain_char:  # # 密码仅包含数字字母
            print('破译密码需要: 153天')
        if contain_alpha and contain_num and contain_char:
            print('破译密码需要: 12年')
elif length == 10:
    if password.isnumeric():
        print('破译密码需要: 40秒')
    if password.isalpha():
        print('破译密码需要: 169天')
    else:
        for i in password:
            if bool(re.findall(i, alpha)):
                contain_alpha = True
            if bool(re.findall(i, num)):
                contain_num = True
            if bool(re.findall(i, char)):
                contain_char = True
        if contain_alpha and contain_num and not contain_char:  # # 密码仅包含数字字母
            print('破译密码需要: 1年')
        if contain_alpha and contain_num and contain_char:
            print('破译密码需要: 928年')
elif length == 11:
    if password.isnumeric():
        print('破译密码需要: 6分钟')
    if password.isalpha():
        print('破译密码需要: 16年')
    else:
        for i in password:
            if bool(re.findall(i, alpha)):
                contain_alpha = True
            if bool(re.findall(i, num)):
                contain_num = True
            if bool(re.findall(i, char)):
                contain_char = True
        if contain_alpha and contain_num and not contain_char:  # # 密码仅包含数字字母
            print('破译密码需要: 106年')
        if contain_alpha and contain_num and contain_char:
            print('破译密码需要: 7万1千年')
elif length == 12:
    if password.isnumeric():
        print('破译密码需要: 1小时')
    if password.isalpha():
        print('破译密码需要: 600年')
    else:
        for i in password:
            if bool(re.findall(i, alpha)):
                contain_alpha = True
            if bool(re.findall(i, num)):
                contain_num = True
            if bool(re.findall(i, char)):
                contain_char = True
        if contain_alpha and contain_num and not contain_char:  # # 密码仅包含数字字母
            print('破译密码需要: 6千年')
        if contain_alpha and contain_num and contain_char:
            print('破译密码需要: 5百万年')
elif length == 13:
    if password.isnumeric():
        print('破译密码需要: 11小时')
    if password.isalpha():
        print('破译密码需要: 2万1千年')
    else:
        for i in password:
            if bool(re.findall(i, alpha)):
                contain_alpha = True
            if bool(re.findall(i, num)):
                contain_num = True
            if bool(re.findall(i, char)):
                contain_char = True
        if contain_alpha and contain_num and not contain_char:  # # 密码仅包含数字字母
            print('破译密码需要: 10万8千年')
        if contain_alpha and contain_num and contain_char:
            print('破译密码需要: 4亿2千3百万年')
elif length == 14:
    if password.isnumeric():
        print('破译密码需要: 4天')
    if password.isalpha():
        print('破译密码需要: 77万8千年')
    else:
        for i in password:
            if bool(re.findall(i, alpha)):
                contain_alpha = True
            if bool(re.findall(i, num)):
                contain_num = True
            if bool(re.findall(i, char)):
                contain_char = True
        if contain_alpha and contain_num and not contain_char:  # # 密码仅包含数字字母
            print('破译密码需要: 2千5百万年')
        if contain_alpha and contain_num and contain_char:
            print('破译密码需要: 50亿年')
elif length == 15:
    if password.isnumeric():
        print('破译密码需要: 46天')
    if password.isalpha():
        print('破译密码需要: 2千8百万年')
    else:
        for i in password:
            if bool(re.findall(i, alpha)):
                contain_alpha = True
            if bool(re.findall(i, num)):
                contain_num = True
            if bool(re.findall(i, char)):
                contain_char = True
        if contain_alpha and contain_num and not contain_char:  # # 密码仅包含数字字母
            print('破译密码需要: 10亿年')
        if contain_alpha and contain_num and contain_char:
            print('破译密码需要: 2万亿年')
elif length == 16:
    if password.isnumeric():
        print('破译密码需要: 1年')
    if password.isalpha():
        print('破译密码需要: 10亿年')
    else:
        for i in password:
            if bool(re.findall(i, alpha)):
                contain_alpha = True
            if bool(re.findall(i, num)):
                contain_num = True
            if bool(re.findall(i, char)):
                contain_char = True
        if contain_alpha and contain_num and not contain_char:  # # 密码仅包含数字字母
            print('破译密码需要: 9百7十亿年')
        if contain_alpha and contain_num and contain_char:
            print('破译密码需要: 193万亿年')
elif length == 17:
    if password.isnumeric():
        print('破译密码需要: 12年')
    if password.isalpha():
        print('破译密码需要: 360亿年')
    else:
        for i in password:
            if bool(re.findall(i, alpha)):
                contain_alpha = True
            if bool(re.findall(i, num)):
                contain_num = True
            if bool(re.findall(i, char)):
                contain_char = True
        if contain_alpha and contain_num and not contain_char:  # # 密码仅包含数字字母
            print('破译密码需要: 6万亿年')
        if contain_alpha and contain_num and contain_char:
            print('破译密码需要: 约无穷年')
elif length == 18:
    if password.isnumeric():
        print('破译密码需要: 126年')
    if password.isalpha():
        print('破译密码需要: 1万亿年')
    else:
        for i in password:
            if bool(re.findall(i, alpha)):
                contain_alpha = True
            if bool(re.findall(i, num)):
                contain_num = True
            if bool(re.findall(i, char)):
                contain_char = True
        if contain_alpha and contain_num and not contain_char:  # # 密码仅包含数字字母
            print('破译密码需要: 374万亿年')
        if contain_alpha and contain_num and contain_char:
            print('破译密码需要: 约无穷年')

随笔记录

侵删

Copyright © 2002-2019 某某自媒体运营 版权所有