Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5931173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:39:26+00:00 2026-05-22T14:39:26+00:00

I have the MD5 hash for a String, stored as a String . I’m

  • 0

I have the MD5 hash for a String, stored as a String. I’m writing a small program to find out the original string by brute force.

I’d like to loop through a subset of char.

The code below works for when String.length() == 0.

I can’t figure out how to edit this code to work with variable-length Strings. I feel like I’m on the right track with recursion, but can’t go any further.

I have the following code:

    public void attempt(String initial, String md5) {

    for (char c = ' '; c < '~'; ++c) {
        attempt = initial + Character.toString(c);
        generatedMd5 = generateMD5(attempt);
        System.out.println(attempt);
        if (hashesMatch(md5, generatedMd5)) {
            break;
        } else attempt(attempt, md5);
    }
}

Note: I should mention this is for an academic study on MD5.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:39:26+00:00Added an answer on May 22, 2026 at 2:39 pm

    You are doing a “Depth first” search (and of unlimited depth!), this is almost guaranteed to fail ( exhausting your stack) if you do not add some depth check.

    You should probably better might want to do a Breadth first search : your loop should first try all the combinations that results in adding a character, and only then, if no success, try to recursively call the method with each augmented string.

    In any case, you should add some depth check, always.

    Edited: thinking it twice, I’m not so sure you should not stick with depth first. Breadth first is only rasonable here for small depths and combinations (character ranges). A possible implementation

      // Breadth first returns null if not found
      public String bruteforce(List<String> prefixes, String md5,int availdepth) {
        if(availabledepth<0) return null;
        List<String> newprefixes = new ArrayList<String>();
        for(String prefix : prefixes) {
            for (char c = ' '; c < '~'; ++c) {
              String attempt = prefix + Character.toString(c);
              generatedMd5 = generateMD5(attempt);
              if (hashesMatch(md5, generatedMd5)) 
                return attempt;
              newprefixes.add(attempt);
           }
        }
        // no success in this level go for next
        return bruteforce(newprefixes,md5,availddepth-1);
      }
    
    
      // Depth first - returns null if not found
      public String bruteforce(String prefix, String md5,int availdepth) {
        if(availdepth <= 0) return null;
        for (char c = ' '; c < '~'; ++c) {
              String attempt = prefix + Character.toString(c);
              if (hashesMatch(md5, generateMD5(attempt))) 
                return attempt;
              String res = bruteforce(attempt, md5, availdepth-1);
              if(res != null) return res;
           }
        return null;
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MD5 hash: 10f86782177490f2ac970b8dc4c51014 http://www.fileformat.info/tool/hash.htm?text=10f86782177490f2ac970b8dc4c51014 Result: c74e16d9 but PHP: crc32('10f86782177490f2ac970b8dc4c51014'); Result: -951183655
Greetings, I have some mysql tables that are currently using an md5 hash as
I have an input field whose name is an MD5 string e.g.: <input type=hidden
Suppose you have a MD5 hash encoded in base64. Then each character needs only
I have this custom function to calculate MD5 hash, written in Java. I can't
My PHP is very rusty. I have a md5 hash that's being passed via
I have created MD5 hash.Its working fine now.I want output in 16 character.Current Code
i want to convert a short string to md5 hash , I found several
Response example for MD5 hash found, for example http://md5.noisette.ch/md5.php?hash=2a0231531bc1a7fc29e2fa8d64352ae9 : <md5lookup> <hash>2a0231531bc1a7fc29e2fa8d64352ae9</hash> <string>noisette</string> </md5lookup>
In http://www.anyexample.com/programming/java/java_simple_class_to_compute_md5_hash.xml an example is given how to calculate an MD5 hash of String.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.