나는 11 학년 컴퓨터 과학 프로젝트를위한 프로그램을 만들었는데, 여기서 자바 패스워드 크래커를 만들었습니다. 그러나, 나는 브루트 - 강제 프로세스를 빠르게하기 위해 자바 프로그램 (코드 제공)을 멀티 스레드하는 법에 대한 조언을 받고 싶다. 내가 인텔에서 i7-3770 프로세서를 돌리고 있으며 쿼드 코어이지만 코어 당 스레드가 2 개이므로 8 개의 가능한 스레드를 동시에 사용할 수 있습니다.무차직 자바 패스워드 프로그램을 멀티 스레드하는 법
import java.util.*;
import java.io.*;
class pwcracker
{
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
Random rand = new Random();
Runtime.getRuntime().availableProcessors();
String pw, choices, guess;
long tries;
int j, length;
System.out.println("Enter a password that is up to 5 chars and contains no numbers: ");
pw = "" + scan.nextLine();
length = pw.length();
choices = "abcdefghijklmnopqrstuvwxyz";
tries = 0;
guess = "";
System.out.println("Your pw is: " + pw);
System.out.println("The length of your pw is: " + length);
System.out.println("for TEST- Guess: " + guess + "pw :"+pw);
if (guess != pw){
while (guess != pw)
{
j = 0;
guess = "";
while (j < length)
{
guess = guess + choices.charAt(rand.nextInt (choices.length()));
j = j + 1;
if (guess == pw)
{
System.out.println("Match found, ending loop..");
break;
}
}
System.out.println("2 Guess: " + guess + " pw :"+pw);
tries = tries + 1;
}
}
System.out.println("Here is your password: " + guess);
System.out.println("It took " + tries + " tries to guess it.");
}
}
자바에서는 문자열을 비교할 때 ==를 사용할 수 없습니다. string1.equals (string2)를 사용해야합니다. – slipperyseal
프로그램이 하이퍼 스레딩되지 않았으며 프로세서가 하이퍼 스레딩되었습니다. 그리고 프로세서 스레드는 코어보다 소프트웨어 쓰레드와 더 이상 관련이 없습니다. – immibis
예, 죄송합니다. 내 말에 .equals 대신 ==를 사용하도록 코드를 업데이트 한 것을 잊어 버렸습니다. 더 이상 버그가 없으므로 –