8 Replies Latest reply: Dec 14, 2009 6:17 AM by jwenting RSS

    Problem with Brute Force

    843853
      I have this code but i can't make it work wright.
      At first I want to find out the correct password with brute force. As a result I take all the possible combination but none of them is the correct even the correct.
      And the next step is to use this code for a program to find out the password in zip file with brute force and dictionary attack.
      Now I work the brute force way and then with the dictionary attack.
      Here is the code:
         1. import java.*;  
         2. public class Brutus {  
         3.   
         4. char[] canUse = {  
         5. '0','1','2','3','4','5','6','7','8','9',  
         6. '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'  
         7. };  
         8.   
         9. int maxlen = 2;  
        10. String code = "aaa";  
        11.     public static void main (String[] args) {  
        12.   
        13.         Brutus b = new Brutus();  
        14.     }  
        15.       
        16.   
        17.     public Brutus() {  
        18.     int k = 0;  
        19.   
        20.     while (k < canUse.length) {  
        21.         nextString(new Character(canUse[k]).toString());  
        22.         k++;  
        23.     }  
        24.   
        25.     }  
        26.   
        27.   
        28.     private void nextString(String s) {  
        29.   
        30.     int i = 0;  
        31.   
        32.     System.out.println(s);  
        33. try{  
        34.     while (i< canUse.length) {  
        35.         System.out.println(s + new Character(canUse).toString()); 
      36.
      37. if (new String(s + new Character(canUse[i]).toString()).length() <= maxlen) {nextString(s + new Character(canUse[i]).toString());}
      38. i++;
      39. if (code == s + new Character(canUse[i]).toString()){ 
      40. System.out.println("This is the password");
      41. }else{ 
      42. System.out.println("This in not the password , try again");
      43. }
      44. }
      45. }catch(Exception e){ 
      46. System.out.println("Exception raised");
      47. }
      48. }
      49. }
      And here is the result:
      
      aa8
      This in not the password , try again
      aa9
      This in not the password , try again
      aaa
      This in not the password , try again
      aab
      This in not the password , try again
      aac
      
      Edited by: mortis1572 on Dec 13, 2009 2:13 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
        • 1. Re: Problem with Brute Force
          jwenting
          Get lost, scripkiddie.
          We're not here to help people crack passwords or do other illegal things.
          • 2. Re: Problem with Brute Force
            843853
            jwenting wrote:
            We're not here to help people crack passwords or do other illegal things.
            I suspect that it is just a homework assignment since the approach would never work in the real world.
            • 3. Re: Problem with Brute Force
              843853
              No i want to make something illegal.
              It is my project.I want to make a program to get the password from a zip file with an aes encryption.
              Firstly I want to make something easy to understand the method of brute force and secondly to use that in the mai program.
              So if anyone know something ploease help me.
              • 4. Re: Problem with Brute Force
                843853
                mortis1572 wrote:
                No i want to make something illegal.
                Did you intend to write "No i *do not* want to make something illegal"?
                • 5. Re: Problem with Brute Force
                  jwenting
                  sabre150 wrote:
                  jwenting wrote:
                  We're not here to help people crack passwords or do other illegal things.
                  I suspect that it is just a homework assignment since the approach would never work in the real world.
                  never overestimate the intelligence of the scriptkiddie :)
                  • 6. Re: Problem with Brute Force
                    jwenting
                    tschodt wrote:
                    mortis1572 wrote:
                    No i want to make something illegal.
                    Did you intend to write "No i *do not* want to make something illegal"?
                    See reply #5 :)
                    • 7. Re: Problem with Brute Force
                      843853
                      Excuse me for my writting.
                      h4. I don't want to make something illegal
                      So if someone want to help me please help me and stop the funny question about illegall and legal.
                      So please stopped it.
                      • 8. Re: Problem with Brute Force
                        843853
                        Mortis1572,
                        The problem with your code is in where you compare the Strings. You are not really comparing the contents of the String object, you are comparing the references and that is why even if the 2 Strings are the same it will not say they are the same. The string of characters may be the same but they are not the same instance of the object.
                        A quick fix would be changing the comparisons to use the String object's compareTo method.
                        if(code.compareTo(s + new Character(canUse).toString()) == 0){
                        // They are the same
                        } else {
                        // They aren't
                        }