python解法,参考里面的写法分别计算,字母,数字和符号的个数,分类讨论,注意讨论细节中间错了很多次

密码强度等级

http://www.nowcoder.com/questionTerminal/52d382c2a7164767bca2064c1c9d5361

encoding:utf-8

if name == 'main':
log = 0
while True:
try:
s = raw_input()
if len(s)<=4:
score = 5
elif len(s)<=7 and len(s)>=5:
score = 10
elif len(s)>= 8:
score = 25
else:
score = 0
num_alpha_up = 0
num_alpha_low = 0
num_digit = 0
num_sym = 0
for i in s:
if i.isdigit():
num_digit=num_digit+1
elif i.islower():
num_alpha_low +=1
elif i.isupper():
num_alpha_up+=1
else:
num_sym+=1
#纯数字
if num_digit == len(s):
if len(s) ==1:
score = score +10
else:
score = score+20
#纯字母
if num_alpha_up +num_alpha_low == len(s):
if num_alpha_low == len(s) or num_alpha_up == len(s):
score = score+10
else:
score =score+20
if log == 1:
print '纯字母,score = ',score
# 纯符号
if num_sym == len(s):
if len(s) == 1:
score = score + 10
else:
score = score + 25
#字母+数字
if num_digit>0 and num_alpha_low+num_alpha_up > 0 and num_sym == 0:
if num_digit+num_alpha_up+num_alpha_low ==len(s):
score = score+2
if num_digit == 1:
score+=10
elif num_digit >1:
score +=20
if num_alpha_up == 0 or num_alpha_low == 0:
score+=10
elif num_alpha_low>0 and num_alpha_up>0:
score+=20
#字母+符号
if num_sym > 0 and num_alpha_up+num_alpha_low > 0 and num_digit == 0:
if num_sym == 1:
score = score+10
elif num_sym >1:
score = score+25
if num_alpha_low == 0 or num_alpha_up == 0:
score = score+10
else:
score = score+20
#数字+符号
if num_digit >0 and num_sym > 0 and num_alpha_up+num_alpha_low == 0:
if num_digit == 1:
score = score +10
elif num_digit >1:
score = score +20
if num_sym == 1:
score = score +10
elif num_sym >1:
score = score+25
#字母+数字+符号
if num_digit>0 and num_alpha_up +num_alpha_low>0 and num_sym>0:
#字母+数字+符号
if num_alpha_low == 0 or num_alpha_up ==0:
score = score+3+10
if log == 1:
print '大字母+数字+符号,score = ', score
# 大小写字母+数字+符号
else:
score = score+5+20
#一个数字
if num_digit == 1:
score += 10
elif num_digit > 1:
score += 20
#一个符号
if num_sym == 1:
score+=10
elif num_sym:
score+=25

            if log == 1:
                print '字母+数字+符号,score = ',score

        # print 'score',score


        if score>= 90:
            print 'VERY_SECURE'
        elif score>=80:
            print 'SECURE'
        elif score>=70:
            print 'VERY_STRONG'
        elif score>=60:
            print 'STRONG'
        elif score>=50:
            print 'AVERAGE'
        elif score>=25:
            print 'WEAK'
        elif score>=0:
            print 'VERY_WEAK'
        else:
            print 'error'
    except:
        break
全部评论

相关推荐

Yushuu:你的确很厉害,但是有一个小问题:谁问你了?我的意思是,谁在意?我告诉你,根本没人问你,在我们之中0人问了你,我把所有问你的人都请来 party 了,到场人数是0个人,誰问你了?WHO ASKED?谁问汝矣?誰があなたに聞きましたか?누가 물어봤어?我爬上了珠穆朗玛峰也没找到谁问你了,我刚刚潜入了世界上最大的射电望远镜也没开到那个问你的人的盒,在找到谁问你之前我连癌症的解药都发明了出来,我开了最大距离渲染也没找到谁问你了我活在这个被辐射蹂躏了多年的破碎世界的坟墓里目睹全球核战争把人类文明毁灭也没见到谁问你了😆
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务