import rarfile
from datetime import timedelta, date
# 定义一个函数来生成指定日期范围内的所有日期
def daterange(start_date, end_date):
for n in range(int((end_date - start_date).days)):
yield start_date + timedelta(n)
# RAR文件路径
rar_path = "path_to_your_file.rar"
# 定义日期范围
start_date = date(2000, 1, 1)
end_date = date(2025, 12, 31)
# 生成所有可能的日期组合
dates = (single_date.strftime("%Y%m%d") for single_date in daterange(start_date, end_date))
# 尝试每一个可能的密码
for date in dates:
for prefix in ["hubei", "HUBEI"]:
password = prefix + date
with rarfile.RarFile(rar_path) as rf:
try:
# 尝试使用当前密码解压RAR文件
rf.extractall(path="path_to_extract", pwd=password)
print(f"Success! The password is {password}")
break
except:
# 如果当前密码不正确,继续尝试下一个密码
continue