Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Reaped: Converting a number back to it's original string (that was hashed to generate that number)

by NodeReaper (Curate)
on Jan 23, 2013 at 13:17 UTC ( #1014898=perlquestion: print w/ replies, xml ) Need Help??
NodeReaper has asked for the wisdom of the Perl Monks concerning the following question:

This node was taken out by the NodeReaper on Jan 23, 2013 at 13:34 UTC
Reason: [choroba]: Reap: Duplicate of Uniquely identifying each & every html template.

You may view the original node and the consideration vote tally.

Comment on Reaped: Converting a number back to it's original string (that was hashed to generate that number)
Re: Converting a number back to it's original string (that was hashed to generate that number)
by Anonymous Monk on Jan 23, 2013 at 13:19 UTC
    This is Python, not Perl. This site is Perlmonks. Also this can't be done.
Re: Converting a number back to it's original string (that was hashed to generate that number)
by marto (Chancellor) on Jan 23, 2013 at 13:22 UTC
Re: Converting a number back to it's original string (that was hashed to generate that number)
by Anonymous Monk on Jan 23, 2013 at 13:23 UTC
    Reap this thread, and don't reply further.
Re: Converting a number back to it's original string (that was hashed to generate that number)
by roboticus (Canon) on Jan 23, 2013 at 13:28 UTC

    Nik:

    How many different strings do you want to convert back and forth? For a 5 digit number, the maximum possible set of strings that you could map back and forth is under a million. It's a pretty straightforward result of the Pigeonhole Principle.

    So if you want to do this, you're going to have to come up with rules to constrain your set of input strings to a set small enough to fit in the number of pigeonholes you have. *AND* you'll have to come up with a unique mapping between those strings and the numbers. (You, not us.)

    The instant you have the possibility of mapping two different strings into the same number, you have lost information, and can no longer tell the two strings apart from the number. There's no way to reliably know which string to map the number to without some other source of information.

    roboticus

    Sorry for the troll food.

      The number of the .html pages are < 100.
      Please DON'T tell me to save both the pin <=> filepath and associate them (that can be done by SQL commands, i know)
      I will not create any kind of primary/unique keys to the database.
      I will not store the filepath into the database, just the number which indicates the filepath(html page).
      Also no external table associating fielpaths and numbers.
      i want this to be solved only by Python Code, not database oriented.

      That is: I need to be able to map both ways, in a one to one relation, 5-digit-integer <=> string

      int( hex ( string ) ) can encode a string to a number. Can this be decoded back? I gues that can also be decoded-converted back because its not losing any information. Its encoding, not compressing.

      But it's the % modulo that breaks the forth/back association.

      So, the question is:

      HOW to map both ways, in a one to one relation, (5-digit-integer <=> string) without losing any information?

        Nik:

        What part of my post was unclear? If you're going to persist, then you, not us, are going to have to figure out the mapping, ensure the constraints on the string, and write the python code.

        I'll speak no more on the topic.

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.

        HOW to map both ways, in a one to one relation, (5-digit-integer <=> string) without losing any information?

        CREATE TABLE pin_to_url ( pin int PRIMARY KEY, url varchar(255) ); SELECT v.*, pu.url FROM visitors v JOIN pin_to_url pu ON pu.pin = v.pin ORDER BY whatever;

        Just store the filename alongside the pin into the table and it'll work pretty well.

        The only other way of mapping string to pin -- apart from the lookup table I've just typed out -- is enumerating over the possible filenames and hashing each in turn, comparing the result to the pin. There's no way around it with the constraints you stubbornly add.

        Oh, by the way, with 100 files and 10k available (random-ish) identification numbers, you might hit the birthday paradox. About 60% probable, I think. You don't want a hashing function -- you want an integer sequence. Databases provide those.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1014898]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (17)
As of 2014-11-24 15:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (142 votes), past polls