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 3605054
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:04:33+00:00 2026-05-18T21:04:33+00:00

I have the following hash function, and I’m trying to get my way to

  • 0

I have the following hash function, and I’m trying to get my way to reverse it, so that I can find the key from a hashed value.

uint Hash(string s)
{
    uint result = 0;
    for (int i = 0; i < s.Length; i++)
    {
        result = ((result << 5) + result) + s[i];
    }
    return result;
}

The code is in C# but I assume it is clear.

I am aware that for one hashed value, there can be more than one key, but my intent is not to find them all, just one that satisfies the hash function suffices.

EDIT :

The string that the function accepts is formed only from digits 0 to 9 and the chars ‘*’ and ‘#’ hence the Unhash function must respect this criteria too.

Any ideas? Thank you.

  • 1 1 Answer
  • 1 View
  • 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-18T21:04:34+00:00Added an answer on May 18, 2026 at 9:04 pm

    Brute force should work if uint is 32 bits. Try at least 2^32 strings and one of them is likely to hash to the same value. Should only take a few minutes on a modern pc.

    You have 12 possible characters, and 12^9 is about 2^32, so if you try 9 character strings you’re likely to find your target hash. I’ll do 10 character strings just to be safe.

    (simple recursive implementation in C++, don’t know C# that well)

    #define NUM_VALID_CHARS 12
    #define STRING_LENGTH 10
    const char valid_chars[NUM_VALID_CHARS] = {'0', ..., '#' ,'*'};
    
    void unhash(uint hash_value, char *string, int nchars) {
      if (nchars == STRING_LENGTH) {
        string[STRING_LENGTH] = 0;
        if (Hash(string) == hash_value) { printf("%s\n", string); }
      } else {
        for (int i = 0; i < NUM_VALID_CHARS; i++) {
          string[nchars] = valid_chars[i];
          unhash(hash_value, string, nchars + 1);
        }
      }
    }
    

    Then call it with:

    char string[STRING_LENGTH + 1];
    unhash(hash_value, string, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function that decodes a URL into a hash comprised of
According to MSDN , a hash function must have the following properties: If two
I have the following: An environment that is working like a hash for rows
I'm trying to do the following say; I have a hash: {word1 => {doc1
i have following code uint32 joaat_hash(uchar *key, size_t len) { uint32 hash = 0;
I have the following piece of JS code within a function that responds to
I have the following piece of JS code within a function that responds to
consider the following situation: I have a string s and hash function H generating
I have the following: $(function() { $('.ajaxloader').click(function(event) { var target = $(this).attr('href'); window.location.hash =
I have the following two Node.js files: //test.js var hash=require('./hash'); var sys=require('sys'); hash.hash(asdf,function(param){ sys.puts(param);

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.