大家好,又见面了,我是你们的朋友全栈君。
一 暴力破解,就是不断生成新的密码去尝试能否破解成功。假如我们的密码位数为3位,其里面的值有可能是0或者1,其产生的密码集的数量为2的3次幂,也就是八个,然后一个一个去破解。而这生成这8个密码的过程就有一个递归规则存在。
我们传入深度deep和对应字符串passwd两个参数,如果深度为1,直接输出字符串passwd,如果深度不为1,把深度deep减一,并把可能存在的字符串集合[0,1]遍历,添加到passwd的后面,重新回到这个递归函数,直到深度deep为1输出。
二 解压压缩文件
网上有对应的jar包去解压压缩文件,但是我这里使用一种比较简单的方法去实现,本地电脑window上装有winrar,java调用本地winrar.exe去解压压缩文件。
其核心代码为:
C:\Program Files\WinRAR\WinRAR.exe x -ibck -hp123 -y F:\\BaiduNetdiskDownload\\yewen4\\a.rar D:\\test\\unrar\\
第一个路径是winrar.exe的路径,第二个路劲是需要解压缩文件的路径地址,第三个是存放的路径。-hp后面的123表示密码。
下面是代码的实现
/**
*
* @param filePath 解压文件路径
* @param targetPath 解压之后存放的路径
* @param passwd 密码
* @return
* @throws Exception
*/
public static int unrar(String filePath,String targetPath,String passwd) throws Exception {
//winrar的执行路径
String rarPath="C:\\Program Files\\WinRAR\\WinRAR.exe";
StringBuilder sb = new StringBuilder();
sb.append(rarPath);
sb.append(" x -ibck -hp");
sb.append(passwd).append(" -y ").append(filePath+" "+targetPath);
Process process;
process = Runtime.getRuntime().exec(sb.toString());
if(process.waitFor() ==0 ){
FileOutputStream fileOutputStream = new FileOutputStream(new File("D:\\test\\unrar\\getPassyewen4.txt"));
String s = "解压后的密码:"+passwd;
fileOutputStream.write(s.getBytes());
fileOutputStream.flush();
fileOutputStream.close();
return 1;
}else{
System.out.println(new Date()+"--失败:"+passwd);
return 0 ;
}
}
/**
* 递归获取密码过程
* @param deep 深度
* @param parent 密码
* @return
* @throws Exception
*/
public static int findpwd(int deep,String parent) throws Exception {
String[] dir ={"q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l",
"z","x","c","v","b","n","m","Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X",
"C","V","B","N","M","1","2","3","4","5","6","7","8","9","0","`","!","@","#","$","%","&","*","(",")","-","_","+","=","[",
"]","{","}","|","\\","\"",":",";","\'","<",">",",",".","?","/"};
if(deep == 1){
if(unrar("","",parent) == 1){
return 1;
}else{
return 0;
}
}else{
for(int j =0;j<dir.length;j++){
if(findpwd(deep-1,parent+dir[j]) ==1 ){
return 1;
}
}
}
return 0;
}
文章最后的总结:
破解的难度跟设置密码的长度有关,破解一位的密码只需要92的1次幂个密码,而破解六位的密码需要92的6次幂个密码,其难度可想而知。所以这里写的内容只供学习参考。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/139685.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...