dcsimg
Results 1 to 5 of 5

Thread: [RESOLVED] restore my string from a hash

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2016
    Posts
    174

    Resolved [RESOLVED] restore my string from a hash

    Is it possible to restore my string from a hash?

    Code:
    internal static uint ComputeStringHash(string s)
            {
                //http://wowdev.jp/?p=873
                //https://qiita.com/Ushio/items/a19083514d087a57fc72
    
                uint FNV_OFFSET_BASIS_32 = 2166136261u;
                if (s != null)
                {
                    for (int i = 0; i < s.Length; i++)
                    {
                        FNV_OFFSET_BASIS_32 = (s[i] ^ FNV_OFFSET_BASIS_32) * 16777619; //FNV_PRIME_32 = 16777619U;
                    }
                }
                return FNV_OFFSET_BASIS_32;
            }

  2. #2
    Frenzied Member PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Newport, UK
    Posts
    1,097

    Re: restore my string from a hash

    Hashes are a one way transformation, you can generate a hash from an input but there is no practical way of getting the input back from a hash.

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,995

    Re: restore my string from a hash

    The fact that hashes are one way is the whole point. The idea is that you take the original data and generate a hash, then you can generate a hash from any other data some time in the future and, if the hashes match, know that the two sets of data match. That's how you use MD5 hashes to verify downloaded files and how you use hashing to authenticate user credentials. If that's not what you want then don't use hashing. Encryption is what you want if you need to go in both directions.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2016
    Posts
    174

    Re: restore my string from a hash

    Understand.
    But Why I can't restore single char such as "a"?

    uint FNV_OFFSET_BASIS_32 = 2166136261u;
    FNV_OFFSET_BASIS_32 = (97 ^ FNV_OFFSET_BASIS_32) * 16777619

    result is 3826002220u

    then I reverse:
    (3826002220u / 16777619) ^ FNV_OFFSET_BASIS_32 = 2166136097

    why not 97 instead of 2166136097?

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,995

    Re: restore my string from a hash

    There is not a 1:1 correspondence between values and hashes, i.e. more than one value may produce the same hash. There are so many possible hashes that the likelihood of your checking two values that are not equal and their producing the same hash is vanishingly small. If multiple values can produce the same hash, there can never be a reliable method to get the original value from a hash.

    Apart from that, hashing was never intended to be a two-way process so the question of why it doesn't work as a two-way process is rather nonsensical. Why would you be actively trying to achieve something using a process that is specifically intended not to be used in that way? Maybe spend your time trying to achieve something sensible.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width