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: Password Hash - Brute Force Test - SHA-1

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    114
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Password Hash - Brute Force Test - SHA-1

    Hi.

    So i have some password hashes for example:

    c2543fff3bfa6f144c2f06a7de6cd10c0b650cae

    The input of the program is one of these hashed codes. What i need to do is use SHA-1 to get the original password and print it out to the user. I am really stuck, so far i have just declared all my password hashes as Strings. Is this right or should they be HexStrings ? Byte Arrays ? Char Arrays ? I am really not sure.

    I have been on to the Wiki page for SHA-1 but i can't really see any formula's to calculate the password.

    Am i also right in saying the format of these hashed passwords is hexadecimal ?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Password Hash - Brute Force Test - SHA-1

    You wouldn't be attempting anything nefarious, would you?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    114
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Password Hash - Brute Force Test - SHA-1

    Lol no, its a school task.

    I should add:

    This should be done using Brute Force Test. I think i might be reading the wrong stuff and going down the wrong routes. I am seeing a lot of MessageDigest.getInstance("SHA-1") . Do you think this is used ?

  4. #4
    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: Password Hash - Brute Force Test - SHA-1

    Quote Originally Posted by KevinWorkman View Post
    You wouldn't be attempting anything nefarious, would you?
    My thoughts exactly.

    Hash algorithms are just that - they are not like encryption which can be encoded and decoded. More often than not, they are one way (eg password -> hash) and there is reasoning behind this. Attempts to decode them will immediately raise suspicion.

  5. #5
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Password Hash - Brute Force Test - SHA-1

    The input of the program is one of these hashed codes. What i need to do is use SHA-1 to get the original password


    The solution is:
    public class BruteForceDecryptSinglePasswordFromSingleBitString
    {
      /**
       * @param args don't bother supplying parameters - it won't effect the chance of success
       * @returns correct answer with non-zero probability, probably
       */
      public static void main(String[] args)
      {
        System.out.println("The password is 'MyDogsNameIsShep'");
      }
    }

    Oh wait, maybe that's not right. Are you sure the exercise wasn't to *guess* the password? That would be a nice undergrad exercise. For that you'd need to write some kind of loop (you could alternatively make random guesses) which generated candidate password strings, transform them with SHA-1 (you will need the fragment of code you posted earlier) and then compare the output to your given hash. If that is the exercise, then I would go with a loop counting up from zero, a character set and a mapping of count to candidate password (Integer.toString(int, int) might be your friend here). Don't run that code on a shared server. If you've got a multi-core PC (who hasn't these days? I bought a FX-8120 recently, coretastic), you could consider chunking the job and multi-threading it. Do it for personal satisfaction, not because it'll increase your chances from hopeless to hopeless-but-with-more-fan-noise.

  6. #6
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Password Hash - Brute Force Test - SHA-1

    Brute force SHA-1? Call me in 130,000 years when you get the result
    School assignments to crack a Caesar cipher, or generate hashes would be plausible, but I highly doubt that brute force cracking would be handed out to pupils.

    Either your tutor wanted to abuse you free labour to supply him with rainbow tables or this isn't a school assignment
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

Similar Threads

  1. Finding Chromatic Number w/ Brute Force Algorithm
    By thecrazytaco in forum Algorithms & Recursion
    Replies: 2
    Last Post: November 16th, 2011, 07:35 AM
  2. Finding Chromatic Number of a Simple Graph w/ Brute Force Algorithm
    By thecrazytaco in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 15th, 2011, 09:27 PM
  3. Force Sync on Graphics2D?
    By Gerp in forum Java Theory & Questions
    Replies: 2
    Last Post: April 13th, 2011, 09:13 PM
  4. JScrollpane - Force autoscroll to top
    By nasi in forum AWT / Java Swing
    Replies: 8
    Last Post: April 18th, 2010, 07:13 PM
  5. Problem with Brute Force
    By mortis1572 in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: March 14th, 2010, 09:52 AM