Δημοσιεύτηκε: 12 Ιουν 2010, 01:14
από mortis1572
Είχες δίκιο η συγκεκριμένη συνάρτηση isProbablyCorrectPassword() όταν είναι είναι σωστό το απότελεσμα επιστρέφει true και επειδή χεησιμοποιούσα και εγώ μια λογική μεταβλητή , εκεί παρουσιάζονταν το πρόβλημα και έβγαζε σαν αποτέλεσμα λάθος κωδικούς και όχι τον σωστό.
Αλλά πάλι δεν καταλαβαίνω γιατί στο δεύτερο κώδικα που έγραψα ενώ βρίσκει τον κωδικό δεν σταματάει το πρόγραμμα , αλλά σταματάει μόνο όταν εμφανίσει όλους τους πιθανούς κωδικούς.
Σαν να μην βλέπει το break ή να έχω ξεχάσει κάποιο break.

Κώδικας: Επιλογή όλων
import java.io.*;
import java.*;
import com.javamex.arcmexer.*;

public class New{
private static char charList[] = {/*'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D',
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z','0',*/'1','2','3','4','5','6','7','8'};
private static int len = 8;
private static String foundWord;
private static String inputLine;
private static boolean stop;

public static void main(String[] args)
{
prompt();
}

public static void prompt()
{
try {
System.out.println("Give the path of the file");
BufferedReader flnm = new BufferedReader(new InputStreamReader(System.in));
inputLine = flnm.readLine();
System.out.println("What is the password of " + inputLine + " ? ");
System.out.println("Working...");
findWord();
System.out.println("The password is: " + foundWord);
}catch (Exception e){
System.out.println("Exception raised!");
e.printStackTrace();
}
}

public static void findWord()
{
StringBuffer sb = new StringBuffer(len);
char currChar = charList[0];
for(int a = 0; a < len; a++)
sb.append(currChar);

cycleChars(0, sb);
}

public static StringBuffer cycleChars(int pos, StringBuffer sb)
{
try{
FileInputStream f = new FileInputStream(inputLine);
ArchiveReader r = ArchiveReader.getReader(f);
ArchiveEntry entry ;
while ((entry = r.nextEntry())!= null){
if (stop == false)
{
for(int i = 0; i < len; i++)
{
sb.setCharAt(pos, charList[i]);
if (pos == len - 1)
{
if (entry.isProbablyCorrectPassword(sb.toString())){
stop = true;
foundWord = sb.toString();
break;
}
}else
cycleChars(pos + 1, sb);
}
}
}
}catch (Exception e){
System.out.println("Exception raised!");
e.printStackTrace();
}