Results 1 to 4 of 4
  1. #1
    PhilArmstrong is offline Member
    Join Date
    May 2008
    Posts
    10
    Rep Power
    0

    Default Trimming a String

    Hi,

    For an assignment I am doing I need to brute force a PBE password.

    I have everything sorted (I think!) except this one last detail.

    How the brute forcing works is that I have a char array of length 10. I have a method that recursively calls itself to check every value in the CharSet (which contains the values that each character can contain):

    Java Code:
    public void changeCharacter(int a) throws Exception
    {
    	int i = 0;
    	while (notGuessed && i < 37)
    	{
    		if (i != 0)
    		{
    			password[a] = charset.getChar(i);
    		}
    		if (a == (passlength-1))
    		{
    			checkPassword();
    		}
    		else
    		{
    			changeCharacter(a+1);
    		}
    		i++;
    	}
    }
    The CharSet has 37 options, 0 is not defined, 1-26 are lowercase letters and 27-36 are numbers.

    When I turn the password into a string it stuffs the (what should be) empty chars with what I assume is lots of '\u0000'.

    So basically my question is how can I get rid of these?
    I tried turning it into a string and calling trim() but that didn't work.
    I tried running this loop, and then just making a substring starting at i
    Java Code:
    while (temp && i < passlength)
    {
    	if (password[i] != '\u0000')
    	{
    		temp = false;
    	}
    	i++;
    }
    which worked fine, up, but once the main loop started searching with passwords of 4 or more, it still only showed 3 characters :s

    So basically any help is greatly appriciated.
    I put it in the beginners section, as although the assignment isn't really a beginners thing, I think the problem I am having probably has a rather easy solution that I cannot see :(

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Initialize your variable 'i' to 1, not to 0 before you start your loop.

    kind regards,

    Jos

  3. #3
    PhilArmstrong is offline Member
    Join Date
    May 2008
    Posts
    10
    Rep Power
    0

    Default

    I tried that, the problem then is that the first password tried is "aaaaaaaaaa" not "a". The idea is that the length of the password isn't known, so i need to try all possible values between "a" and "0000000000" (which is the last possible combination)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by PhilArmstrong View Post
    I tried that, the problem then is that the first password tried is "aaaaaaaaaa" not "a". The idea is that the length of the password isn't known, so i need to try all possible values between "a" and "0000000000" (which is the last possible combination)
    Build another loop around your recursive method that indicates the length of the wanted passwords, so don't go up all the way to the length to of that array but up to a value, say, length (it must be another parameter to your method). That loop increments the length variable from 1, 2, 3 ...

    kind regards,

    Jos

Similar Threads

  1. Replies: 3
    Last Post: 11-09-2009, 07:19 AM
  2. Replies: 7
    Last Post: 11-03-2009, 02:18 AM
  3. Trimming URL
    By Juuno in forum New To Java
    Replies: 1
    Last Post: 03-10-2009, 05:17 PM
  4. Replies: 5
    Last Post: 01-11-2009, 10:12 AM
  5. Replies: 0
    Last Post: 11-20-2007, 04:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •