Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Can I get the original string from a HashCode?

Can I get the original string from a HashCode?

Scheduled Pinned Locked Moved C#
csharpcomquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dekelc
    wrote on last edited by
    #1

    Hello!! Can I get the original string from a HashCode? I mean, do the reverse action of GetHashCode. thanks :confused: Scan files and folders for viruses from your .Net applications - Click here!

    J G 2 Replies Last reply
    0
    • D dekelc

      Hello!! Can I get the original string from a HashCode? I mean, do the reverse action of GetHashCode. thanks :confused: Scan files and folders for viruses from your .Net applications - Click here!

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      I don't think that's possible. The hash code simply could not be unique enough to support all possible strings. If you want to store string and hash code pairs, use a System.Collections.Generic.Dictionary<int, string> to store them together. You can then easily retrieve strings via dictionary[hashCode].

      W 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        I don't think that's possible. The hash code simply could not be unique enough to support all possible strings. If you want to store string and hash code pairs, use a System.Collections.Generic.Dictionary<int, string> to store them together. You can then easily retrieve strings via dictionary[hashCode].

        W Offline
        W Offline
        Werdna
        wrote on last edited by
        #3

        It's totally not possible. The hashing function is always one way. Since int can only have about 2.2B possible values, there is way more than 2.2B possible string combinations.

        J 1 Reply Last reply
        0
        • D dekelc

          Hello!! Can I get the original string from a HashCode? I mean, do the reverse action of GetHashCode. thanks :confused: Scan files and folders for viruses from your .Net applications - Click here!

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          No, it's not possible. Just image if it was... You could put any data into a string and compress it to 32 bits. There would be no need for fast internet connections or large hard drives... --- b { font-weight: normal; }

          1 Reply Last reply
          0
          • W Werdna

            It's totally not possible. The hashing function is always one way. Since int can only have about 2.2B possible values, there is way more than 2.2B possible string combinations.

            J Offline
            J Offline
            Judah Gabriel Himango
            wrote on last edited by
            #5

            Yep, my thoughts exactly.

            Tech, life, family, faith: Give me a visit. I'm currently blogging about: How 'bout a little guitar now? The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups