1.破解六位数字的密码
废话不多说,给我上代码!
key = input('请输入六位数密码:') #填写密码用来破解
while len(key)!=6: #判断密码是否为六位,否则重新输入
print('密码不合法,请重新输入!')
key = input('请输入六位的密码:')
print(key)
key = list(key)
print('设置的密码为:',key)
my_str = []
result = ['0','0','0','0','0','0']
#数字0-9的ASCII码为48-57
for j in range(48,58):
my_str.append(chr(j))
for i in my_str:
result[0] = i
for j in my_str:
result[1] = j
for k in my_str:
result[2] = k
for l in my_str:
result[3] = l
for m in my_str:
result[4] = m
for n in my_str:
result[5] = n
if result == key:
print('破解成功!密码为:',result)
break
else:
print('失败',result)
else:
continue
break
else:
continue
break
else:
continue
break
else:
continue
break
else:
continue
break
2.破解六位数字大小写字母混合密码
key = input('请输入六位数密码:') #填写密码用来破解
while len(key)!=6:
print('密码不合法,请重新输入!')
key = input('请输入六位的密码:')
key = list(key)
print('设置的密码为:',key)
my_str = []
result = ['0','0','0','0','0','0']
#产生数组进行比对 a = random.choice(my_str)
for j in range(48,123):
if j in [58,59,60,61,62,63,64,91,92,93,94,95,96]:
continue
my_str.append(chr(j))
# print(my_str)
for i in my_str:
result[0] = i
for j in my_str:
result[1] = j
for k in my_str:
result[2] = k
for l in my_str:
result[3] = l
for m in my_str:
result[4] = m
for n in my_str:
result[5] = n
if result == key:
print('破解成功!密码为:',result)
break
else:
print('失败',result)
else:
continue
break
else:
continue
break
else:
continue
break
else:
continue
break
else:
continue
break
提示:本方法为穷举法破解六位密码,但基于方法本身的缺陷,如果密码开头过大,会导致运行起来过慢,需要很长时间来破解,如876sG5这样以8这样比较大的数字开头就比较费时间。但是,本方法的优是不论耗费多长时间,总会、一定会破解成功。
学习笔记:
1.使用以下方法实现了break跳出嵌套的for循环(多层for循环)
for i in range(1,5):
for j in range(5,10):
print(i,j)
if j==6:
break
else:
continue
break
2.数字和字母对应的ASCII码为
a-z 97-122
A-Z 65-90
0-9 48-57
数字、字母转ASCII码函数:ord()
ASCII码转数字、字母函数:chr()
3.从列表中产生随机数
my_str = ['h','e','l','i','o']
a = random.choice(my_str)
print(a)