摘要:看我如何用 20 行让女神对我转变态度的…
本文分享自华为云社区《女神相册密码忘记了,我只用Python写了20行代码~~~》,原文做者:LexSaints 。python
今早上班,公司女神小姐姐说,她去年去三亚旅游的照片打不开了,好奇问了一下才知道,原来是,她把照片压缩了,并且还加了密码。可是密码不记得了,只记得是一串 6 位数字。话说照片压缩率也不高,并且还加密,难道是有什么可爱的小照片。segmentfault
可是做为一个正(ba)直(gua)的技术人员,我跟她说:“这事交给我,python 写个脚本,帮你破解掉~~”测试
对相册进行压缩的时候,添加了密码。LIke This ↓加密
打开的时候,提示这样的,须要输入密码。spa
首先若是想要 python 命令行来打开小姐姐相册,那么首先要找到尝试打开的命令行,即解压缩时使用的命令行。而后咱们使用 python 脚本写嵌套循环,不断的对 zip 文件进行尝试解压,而后找回真实的密码。命令行
首先压缩文件是 zip 格式的,咱们使用万能的 7z 命令来进行解压。code
为何不用 unzip 命令呢?(由于我试过了,unzip 没法循环)blog
#7Z详细参数,下面只截取几个关键参数PS C:\Users\lex> 7z7-Zip 21.01 alpha (x64) : Copyright (c) 1999-2021 Igor Pavlov : 2021-03-09Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...] [@listfile]<Commands> a : Add files to archive #加入压缩 d : Delete files from archive e : Extract files from archive (without using directory names) t : Test integrity of archive #尝试密码,不解压...<Switches> -o{Directory} : set Output directory -p{Password} : set Password #设置密码参数
命令太简单,感受都有点配不上个人才华和思路ip
7z -p 123456 t 三亚相册.zip# t:尝试打开,相似后台运行# -p:尝试的密码# 最后是要解压的文件
根据小姐姐的需求,密码是 6 位纯数字,那就帮我节省了好大一段时间,只对 6 位纯数字进行尝试就能够了。三分钟就把脚本搞出来了utf-8
# -*- coding:utf-8 -*- import osimport subprocessimport zipfiledef brutecrack(): for a in range(1,10): for b in range(1,10): for c in range(1,10): for d in range(1,10): for e in range(1,10): for f in range(1,10): passwd=str(a)+str(b)+str(c)+str(d)+str(e)+str(f) command='7z -p'+passwd+' t F:/三亚相册.zip' #t 表示test,不进行实际解压,只测试密码 print(passwd) child=subprocess.call(command) #os.popen(command)#这个也能够用,可是很差监控解压状态 print(child) if child==0: print("相册密码为:"+passwd) returnif __name__ == '__main__': brutecrack()
面对着束手无策的女神,我运行起了脚本,不到 5 秒,相册成功打开了。效果 gif ↓
打开以后,女神看个人眼神都变了。