" Teach you how to use brute force "
This article is a continuation of the previous issue of compressed files. In this issue, we will discuss how to brute force the crack without knowing the password.
Last review: How to decrypt compressed files through python
01— Prepare materials
The preparation materials for this issue are relatively small, and they are all basic codes.
1. Master the basic for loop and if judgment.
2. Master the usage of recursion.
02— Implementation Principle
Let's discuss the realization principle of brute force cracking!
First, let's take a look at how many combinations of the two numbers 1,2 digits below two digits.
Yes, there are 6 types: 1, 2, 11, 12, 21, 22.
If it is 123, how many two-digit combinations are there?
12 kinds, namely: 1, 2, 3, 11, 12, 13, 21, 22, 23, 31, 32, 33
Another way:
Our password is 1 digit, how many situations are there!
The answer is 10 kinds, and so is 0. Password from 0 to 9
Then if the password we set is two digits, how many situations are there!
The answer is 100 kinds. Numbers from 00 to 99.
Then we found a rule, for this simple operation, then we can use a for loop to solve.
code show as below:
"""纯数字密码破解"""
#这种情况不包含000001的情况。
zip_file = zipfile.ZipFile("zip.zip")
zip_list = zip_file.namelist() # 得到压缩包里所有文件
for i in range(9999):
x=str(i)
y=False
for f in zip_list:
try:
zip_file.extract(f, "zip",x.encode('utf-8')) # 循环解压文件到指定目录
print("密码正确,密码是"+x)
y=True
except BaseException as e:
print("密码输入错误"+x)
break
if y==True:
break
zip_file.close() # 关闭文件,必须有,释放内存
The above is a pure digital cracking method, let's implement the situation that is not a pure password
list=[1,2,3]
for i in list:
print(i)
for j in list:
print(i+j)
for y in list:
print(i+j+y)
The above is the basic principle. According to the needs, we can add the required digits by ourselves. The above is all cases below 3 digits.
After reading the above code, we want to simplify the operation. If the password has 60 digits, don't we have to write 60 for loops.
Then let's take a look at the upgraded version:
"""字符串暴力破解"""
# 包含000001的情况。
# zmb="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
zmb = "abcdefg"
list = zmb.replace("", " ").split()
def blpj(list, num=2, x="", a=1, y=[]):
a += 1
for j in list:
y.append(x + j) # print(x+j)
if a != num + 1:
blpj(x=x + j, num=num, a=a, list=list)#内部调用自己,递归处理
return len(y), y#返回一个密码组合列表。
print(blpj(list, num=4))#调用并打印,list根据自己的想要填下,比如是数字,或者只有字母
At this point, the brute-force cracking algorithm is over.
related suggestion:
Hidden confession skills, python teaches you how to use picture exif information to hide confession
Two-dimensional code confession of the little secrets in the two-dimensional code
Scan the QR code below, follow us and learn more about interesting programming.