Программа для расчета времени перебора пароля возвращает 0 или 4009813075 секунд. - PullRequest
0 голосов
/ 10 сентября 2018

Я решил, что сделаю программу, которая будет оценивать время, которое потребуется для перебора пароля SHA256 с помощью GTX 1070. Предположительно, у меня есть все, что мне нужно набрать, но оно будет возвращать только 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");
}
}
}
...