Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: CycleChars

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default CycleChars

    Hello.
    I have a table with 3 elements.e.g String table{"a","b","c"}
    And I want the result to be like this:
    aaa
    aab
    aac
    aba
    abb
    abc
    .
    .
    .
    ccc
    But I don't know how to do this.I would like to do this because I want to make a program to find out the password of some files with brute force.
    If anyone know please help me.

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: CycleChars

    I don't know, hacking passwords.... Use a nested for loop to loop through each value of the array.

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: CycleChars

    ... it will take forever to crack a password using brute strength unless it is ridiculously short and is limited in a severely small amount of possible characters.

    With the standard set of letters, numbers, and some punctuation, that's ~100 different characters per spot (give or take a lot), and with passwords at 8 or less digits long (many are much, much longer), that's 100^8 + 100^7 + 100^6 ... + 100 + 1 different combinations for a simplepassword, meaning if you calculated a password every nano-second it would take roughly 32 years to try every combination.

    If it's your own password, it'd be much better to simply ask for a security question if you forget rather than try to "brute-force" your way to the solution. If it's someone else's... maybe it's better you didn't at all

    However, as a homework assignment, with a very limited set, you could use some for-loops (iterating between each digit and each possible value for that digit) to get a brute-strength algorithm.

  4. #4
    Junior Member
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: CycleChars

    Yes it's a homework assignment.
    I use only digits from 0 to 8.
    I wrote a program but my problem is that doesn't found the correct paswword.
    I have a zip file with aes encryption and the code is (12345678) but the program doesn't found it.
    Ιnstead of this it presents another codes.I discovered when the 3 first digits it isn't the digit 1 then presents the problem e.g(22111111,12222222).If the code is e.g(11114444,11112345) it founds it.
    But whatever I select as a code it doesn't found it.
    Here is my code:

    import java.io.*;
    import java.*;
    import com.javamex.arcmexer.*;
     
    public class Geo{
      private static char fCharList[] = {'1','2','3','4','5','6','7','8'};
      private static int len = 8;
      private static boolean stop;
      private static String foundWord;
     
      public static void Brute() 
        {
            StringBuffer sb = new StringBuffer(len);
            char currentChar = fCharList[0];
            for (int i = 0; i < len; i++)
            {
                sb.append(currentChar);
            }
     
            ChangeCharacters(0, sb);
            }
     
        public static StringBuffer ChangeCharacters(int pos, StringBuffer sb)
      {
           try {
    FileInputStream f = new FileInputStream("C://op3.zip");
    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, fCharList[i]);
                if (pos == len - 1)
                {
                 if (entry.isProbablyCorrectPassword(sb.toString())){
                    stop = true;
                foundWord = sb.toString();
                break;
                }
                }else
                {
                    ChangeCharacters(pos + 1 , sb);
                }
            }
        }     
    }
    }catch (Exception e){
    System.out.println("Exception raised!");
    e.printStackTrace();
    }
     return sb;
      }
        public static void Read(){
            try {
    System.out.println("Working...");
        Brute();
        System.out.println("The password is: " + foundWord);
        }catch (Exception e){
    System.out.println("Exception raised!");
    e.printStackTrace();
    }
        }
        public static void main(String[] args) {
            Read();
        }
    }

  5. #5
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: CycleChars

    I suggest you take a trivial length password, e.g. 3 characters, and step through your code by hand with pencil and paper, keeping track of the variables. It shouldn't take you more than a few minutes to see what's wrong.

  6. #6
    Junior Member
    Join Date
    Jan 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: CycleChars

    The previous problem , i had with the brute force was solved.Here is the code:

    import java.io.*;
    import java.*;
    import com.javamex.arcmexer.*;
     
    public class Brute_Force{
      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 ok=true;
     
      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 + " ? ");
        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 && ok!=false){
       for(int i = 0; i < charList.length; i++){
            sb.setCharAt(pos, charList[i]);
            if (pos == len - 1){
                if (entry.isProbablyCorrectPassword(sb.toString())){
                foundWord = sb.toString();
                System.out.println("possible password found:"+foundWord);
                entry.setPassword(foundWord);
                InputStream in = entry.getInputStream();
                try{
                           in.read();
                           ok=false;
                           System.out.println("This is the password!!");
                        }catch(Exception ee)  {
                            ok=true;
                            System.out.println("This in not the password , try again");
                        }
                    }
            }else
              cycleChars(pos + 1, sb);
          }
    }
    }catch (Exception e){
    System.out.println("Exception raised!");
    e.printStackTrace();
    }
        return sb;
      }
    }

    Now I want the program not search all the charList[] but only the selection I want between the numbers,lower letters,upper letters and all of them.I want to make something like a selection list , that user select.I think that I need 4 more tables.One with the lower letters , one with uperr letters , one with the digits and one more.In last table they will be placed the selection from user.
    And my other opinion is to use only one more table to place the selection from user.But I don't know how to get the selection from user and fill in the table. e.g If the user write a,1 then , the second table must fill with lower letters and numbers.So the brute force will be run only for the selections and not all the table.
    So the program will be much faster and not search all the table without reason.