java - 如何修复我的代码以破解字母、数字和特殊字符密码
问题描述
我正在做一个科学项目,我设置了一个程序来破解代码并显示计算机需要多长时间才能找到它,但它只适用于数字。我希望代码能够破解混合数量的密码任何顺序的特殊字符、字母和数字。我有点难过并且很长时间以来一直很沮丧,所以任何可以编辑并向我发送修改后的代码(或向我展示我做错了什么并提供解决方案)的人将不胜感激。提前致谢!
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
public class consolePrint {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Type in a password!\n");
//guess cannot be resolved to a variable??
//prompt for pin,new line
// Commented out old input code String password =
System.console().readLine(); //Read input to password string
Scanner sc = new Scanner (System.in);
String password= sc.nextLine();
/* Can only run 1- {insert set number}
-Protect input from bad data (ABC, etc) non-digits and or > 9 digits
[Prevent]
-Master loop to keep request new input after reach run and clear the
screen *hint loop starts before 'set pin' prompt
*/
long startTime = System.nanoTime(); // get time just before loop starts in nanoseconds to calculate speed
for(int guess=0;guess<=1000000000;guess++) //start guess at 0 run until less than or equal 10,000 and add one each time to guess [9 digits]
{
//System.out.println("Guess#");
//System.out.println(guess);
if (password.equals(Integer.toString(guess)))
{
System.out.print("Nice! found in ");
System.out.print((System.nanoTime()-startTime)/1000000000.0); //start time in nanoseconds subtracted from end and converted to seconds
System.out.println(" seconds");
break;
}
else
{
//System.out.println(" Sorry, wrong pin!");
}
}
}
}
解决方案
看起来很简单,但你的 for 循环只产生数字猜测。您不能期望在不生成具有混合模式的估计的情况下猜测具有混合模式的密码。你的猜测必须包括特殊字符和字母,你需要想办法产生这样的猜测。
做到这一点的一种方法是手头上有一系列可能的字符。首先将您猜测的每个字符设置为数组中第一个可能的字符。接下来,您应该通过跨越字符数组来更改每个字符。当然,猜测的数量和所需的时间将远远超过当前。
推荐阅读
- python - 如何使用需要多列作为参数的函数创建新列
- arrays - 用 awk 合并 2 个文件,同时用 'NA' 填充缺失值
- python - 获取 pandas 中列的值计数。接收错误:AttributeError:“元组”对象没有属性“value_counts”
- python - 如何将解码器 LSTM 的输出数据转换回单词?
- r - 在 R 中删除数据表中的空列的最有效方法是什么
- python - 如何自动调整重要部分的绘图大小,而不显示白色部分?
- python - 我的外键使用正确吗?还是我需要不同的查询?
- python - 包含需要在 Django 中预先排序的多对多字段的排序对象
- kubernetes - Nginx Ingress 返回 413 Entity Too Large
- python - 在Python中选择一组随机索引后如何获取剩余索引?