Java 用于计算暴力破解密码的时间的程序返回0或4009813075秒

Java 用于计算暴力破解密码的时间的程序返回0或4009813075秒,java,exponent,Java,Exponent,我决定制作一个程序,估计用GTX 1070暴力破解SHA256密码所需的时间。大概,我已经输入了所有需要的内容,但它只会返回0或4009813075秒(128年10个月29天20小时57分55秒) 我认为问题可能出在第66行,因为我计算了该长度和密码类型的符号组合的总数,然后将其转换为long(可能有些数字太大了,不适合long?)。无论如何,也许我不应该在我的第一次作业中使用大指数,但我希望我能让其他人看看这个,告诉我他们的想法 import java.util.Scanner; publi

我决定制作一个程序,估计用GTX 1070暴力破解SHA256密码所需的时间。大概,我已经输入了所有需要的内容,但它只会返回0或4009813075秒(128年10个月29天20小时57分55秒)

我认为问题可能出在第66行,因为我计算了该长度和密码类型的符号组合的总数,然后将其转换为long(可能有些数字太大了,不适合long?)。无论如何,也许我不应该在我的第一次作业中使用大指数,但我希望我能让其他人看看这个,告诉我他们的想法

import java.util.Scanner;

public class Hashtime {

public static void main(String[] args) {
    System.out.println("The purpose of my program will be to estamate the required time to crack a SHA256 password using a GTX 1070,\nmore specifically based on the real world performance of the ASUS STRIX GTX 1070 in my desktop.\n");
    // TODO Auto-generated method stub
long GTX_1070_SHA256_HASHRATE = 2300200000L; //The hash rate constant in hash per second
int pass_len; //length of the password as given from the user
int pass_type; //Represents what the password consists of
int pass_power; //Found from pass_type, it is the number of symbols that could be at each location in the password
long pass_combo; //found as the product of pass_len and pass_power, it is the total number of combos that your password could be
long time_sec; //total number of seconds required to brute force all combos

// The following variables combined together equal time_sec. Example, 10 days 23 hours 10 minutes and 57 seconds
long time_years_t;
int time_months_t;
int time_days_t;
int time_hours_t;
int time_minnutes_t;
int time_seconds_t;
int mod_time; //remaining time after division to find values
int mod_time_b; //When I need to keep the old mod and calculate a new mod
Scanner scn = new Scanner(System.in); //initiates scanner

System.out.println("What is the length of your password?");
pass_len = scn.nextInt(); //Determines the length of the password by promoting the user
System.out.println("");

System.out.println("What is contained in your password? (Enter the matching number)\n1) Lower Case Only\n2) Upper Case Only\n3) Lower and Upper Case\n4) Lower Case and numbers\n5) Upper Case and numbers\n6) Lower Case, Upper Case, and Numbers\n7) Just Numbers");
pass_type = scn.nextInt(); //Determines how the password is constructed to determine the character set
System.out.println("");

//*********************Find pass_power***********************************//
if(pass_type == 1) {
    pass_power = 26;
}
else if(pass_type == 2) {
    pass_power = 26;
}
else if(pass_type == 3) {
    pass_power = 26+26;
}
else if(pass_type == 4) {
    pass_power = 26+10;
}
else if(pass_type == 5) {
    pass_power = 26+10;
}
else if(pass_type == 6) {
    pass_power = 26+26+10;
}
else if(pass_type == 7) {
    pass_power = 10;
}
else {
System.out.println("Sorry, you entered an invalid number");
    pass_power = -1;
}
//**********************end find pass_power******************************//

if(pass_power == -1) {

}
else {
    pass_combo = (long) Math.pow(pass_len, pass_power); //Finds the total number of possible combinations of characters that your password could be
    time_sec = pass_combo / GTX_1070_SHA256_HASHRATE;

    //********Years*******//
    mod_time = (int) (time_sec % 31104000);
    time_years_t = (time_sec - mod_time)/31104000;
    //*******Months*******//
    mod_time_b = mod_time % 2592000;
    time_months_t = (mod_time - mod_time_b) / 2592000;
    //********Days********//
    mod_time = mod_time_b % 86400; //finding the remainder of time_sec after dividing by the number of seconds in a day
    time_days_t = (mod_time_b - mod_time) / 86400; //finds the number of days, less the remainder
    //********hours*******//
    mod_time_b = mod_time % 3600; ////finding the remainder of mod_time (days remainder) after dividing by the number of seconds in an hour
    time_hours_t = (mod_time - mod_time_b) / 3600;//finds the number of hours less the remainder
    //*******Minutes******//
    mod_time = mod_time_b % 60;//finding the remainder of time_sec after dividing by the number of seconds in a minute
    time_minnutes_t = (mod_time_b - mod_time) / 60;//finds the number of minnutes less the remainder
    //*******Seconds******//
    time_seconds_t = mod_time;


    System.out.println("Your password will take no longer than "+time_years_t+" years, "+time_months_t+" months, "+time_days_t+" days, "+time_hours_t+" hours, "+time_minnutes_t+" minutes, "+time_seconds_t+" seconds to crack with a GTX 1070\n");
}
}
}

是时候掌握一步一步的调试了,我明白了,如果数学中的数字太大,那么它就是无穷大。。。我需要看看如何解决这个问题,或者尝试一些不同的东西可能会更容易。我不是一个Java爱好者,但这似乎就是你想要的。是的,我现在正在研究这个问题,但是你不能用BigIntiger正常地加/减/乘/除等,所以我现在正在研究这个问题(1)是的,您的数字对于
long
来说太大了,但是在这里尝试精确是愚蠢的,因此您可以使用
double
甚至
float
而不是
biginger
(顺便说一句,它有
pow
方法)(2)您计算的值错误:它应该是choices^length而不是length^choices,即如果我有一个由三个大写字母组成的字符串,每个字母有26种可能性,因此字符串的可能性为26 x 26 x 26=pow(26,3)