Converting a string to a number by using INT (no hash method)

Discussion in 'Python' started by Ferrous Cranus, Jan 22, 2013.

  1. I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :(

    And the best part is that "that" number must be able to turn back into a path.

    This way i DON'T EVEN HAVE TO STORE THE ACTUAL HTML PAGE'S ABSOLUTE PATH!!!!

    1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page)
    2. I turn the path into a 4-digitnumber
    3. i store that number to the database. I DONT EVEN HAVE TO STORE THE PATH TO THE DATABASE ANYMORE!!! this is just great!
    Ferrous Cranus, Jan 22, 2013
    #1
    1. Advertising

  2. > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :(
    >
    > And the best part is that "that" number must be able to turn back into a path.
    >
    > This way i DON'T EVEN HAVE TO STORE THE ACTUAL HTML PAGE'S ABSOLUTE PATH!!!!
    >
    > 1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page) 2. I turn the path into a 4-digitnumber 3. istore that number to the database. I DONT EVEN HAVE TO STORE THE PATH TO THE DATABASE ANYMORE!!! this is just great!


    Without involving some kind of lookup table/map service to store the paths (which would entirely defeat the purpose) what you are ranting about is technically impossible. If you tried really really hard you *might* be able to convert a string that long into some kind of 4-digit integer checksum, but you would *never* be able to convert that back into a file path. Nor would it be guaranteed to be unique.
    Leonard, Arah, Jan 22, 2013
    #2
    1. Advertising

  3. On 22/01/2013 16:15, Ferrous Cranus wrote:
    > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :(
    >
    > And the best part is that "that" number must be able to turn back into a path.
    >
    > This way i DON'T EVEN HAVE TO STORE THE ACTUAL HTML PAGE'S ABSOLUTE PATH!!!!
    >
    > 1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page)
    > 2. I turn the path into a 4-digitnumber
    > 3. i store that number to the database. I DONT EVEN HAVE TO STORE THE PATH TO THE DATABASE ANYMORE!!! this is just great!
    >


    Hi Iron Skull,

    I hereby nominate you for Troll of the Millenium.

    --
    Cheers.

    Mark Lawrence
    Mark Lawrence, Jan 22, 2013
    #3
  4. Ferrous Cranus

    Dave Angel Guest

    On 01/22/2013 11:15 AM, Ferrous Cranus wrote:
    > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :(
    >
    > And the best part is that "that" number must be able to turn back into a path.
    >
    > This way i DON'T EVEN HAVE TO STORE THE ACTUAL HTML PAGE'S ABSOLUTE PATH!!!!
    >
    > 1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page)
    > 2. I turn the path into a 4-digitnumber
    > 3. i store that number to the database. I DONT EVEN HAVE TO STORE THE PATH TO THE DATABASE ANYMORE!!! this is just great!
    >


    I had prepared a detailed response, showing what your choices are with
    this new constraint. But I can see from this post here that there's no
    point, so I've thrown it out.

    Either you're trolling, or you have a very limited knowledge of
    mathematics. This isn't a programming problem, it's a simple problem
    of information theory.

    Unless you constrain your users to very restrictive filenames, what you
    ask here simply cannot be done.

    Perpetual motion machine, anyone? Or a compression algorithm which can
    be applied repeatedly to a chunk of data until it shrinks down to one
    byte? No way to do it without cheating, and the literature is full of
    examples of people cheating.


    --
    DaveA
    Dave Angel, Jan 22, 2013
    #4
  5. Τη ΤÏίτη, 22 ΙανουαÏίου 2013 6:27:32 μ.μ. UTC+2, οχÏήστης Leonard, Arah έγÏαψε:
    > > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :(

    >
    > >

    >
    > > And the best part is that "that" number must be able to turn back into a path.

    >
    > >

    >
    > > This way i DON'T EVEN HAVE TO STORE THE ACTUAL HTML PAGE'S ABSOLUTE PATH!!!!

    >
    > >

    >
    > > 1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page) 2. I turn the path into a 4-digitnumber 3.i store that number to the database. I DONT EVEN HAVE TO STORE THE PATH TOTHE DATABASE ANYMORE!!! this is just great!

    >
    >
    >
    > Without involving some kind of lookup table/map service to store the paths (which would entirely >defeat the purpose) what you are ranting about is technically impossible. If you tried really >really hard you *might* be able to convert a string that long into some kind of 4-digit integer >checksum, but you would *never* be able to convert that back into a file path. Nor would it be >guaranteed to be unique.


    Now that iam thinking of it more and more, i don't have to turn the 'path' back to a 'number'

    So, what i want is a function foo() that does this:

    foo( "some long string" ) --> 1234

    =====================
    1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page)
    2. turn the 'path' to 4-digit number and save it as 'pin' (how?)
    3. i store that number to the database. I DONT EVEN HAVE TO STORE THE HTML PAGE'S PATH TO THE DATABASE ANYMORE!!! this is just great!


    At some later time i want to check the weblog of that .html page


    1. request the page as: http://mydomain.gr/index.html?show=log
    2. .htaccess gives my script the absolute path of the requested .html file
    3. turn the 'path' to 4-digit number and save it as 'pin' (this is what i'am asking)
    4. select all log records for that specific .html page (based on the 'pin'column)


    Since i have the requested 'path' which has been converted to a database stored 4-digit number, i'am aware for which page i'am requesting detailed data from, so i look upon the 'pin' column in the database and thus i know which records i want to select.

    No need, to turn the number back to a path anymore, just the path to a number, to identify the specific .html page

    Can this be done?
    Ferrous Cranus, Jan 22, 2013
    #5
  6. Τη ΤÏίτη, 22 ΙανουαÏίου 2013 6:27:32 μ.μ. UTC+2, οχÏήστης Leonard, Arah έγÏαψε:
    > > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :(

    >
    > >

    >
    > > And the best part is that "that" number must be able to turn back into a path.

    >
    > >

    >
    > > This way i DON'T EVEN HAVE TO STORE THE ACTUAL HTML PAGE'S ABSOLUTE PATH!!!!

    >
    > >

    >
    > > 1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page) 2. I turn the path into a 4-digitnumber 3.i store that number to the database. I DONT EVEN HAVE TO STORE THE PATH TOTHE DATABASE ANYMORE!!! this is just great!

    >
    >
    >
    > Without involving some kind of lookup table/map service to store the paths (which would entirely >defeat the purpose) what you are ranting about is technically impossible. If you tried really >really hard you *might* be able to convert a string that long into some kind of 4-digit integer >checksum, but you would *never* be able to convert that back into a file path. Nor would it be >guaranteed to be unique.


    Now that iam thinking of it more and more, i don't have to turn the 'path' back to a 'number'

    So, what i want is a function foo() that does this:

    foo( "some long string" ) --> 1234

    =====================
    1. User requests a specific html page( .htaccess gives my script the absolute path for that .html page)
    2. turn the 'path' to 4-digit number and save it as 'pin' (how?)
    3. i store that number to the database. I DONT EVEN HAVE TO STORE THE HTML PAGE'S PATH TO THE DATABASE ANYMORE!!! this is just great!


    At some later time i want to check the weblog of that .html page


    1. request the page as: http://mydomain.gr/index.html?show=log
    2. .htaccess gives my script the absolute path of the requested .html file
    3. turn the 'path' to 4-digit number and save it as 'pin' (this is what i'am asking)
    4. select all log records for that specific .html page (based on the 'pin'column)


    Since i have the requested 'path' which has been converted to a database stored 4-digit number, i'am aware for which page i'am requesting detailed data from, so i look upon the 'pin' column in the database and thus i know which records i want to select.

    No need, to turn the number back to a path anymore, just the path to a number, to identify the specific .html page

    Can this be done?
    Ferrous Cranus, Jan 22, 2013
    #6
  7. On Tue, 22 Jan 2013 16:27:32 +0000
    "Leonard, Arah" <> wrote:
    > > I just need a way to CONVERT a string(absolute path) to a 4-digit
    > > unique number with INT!!! That's all i want!! But i cannot make it
    > > work :(


    Why bother? Just wish for a zillion dollars and then you never have to
    program again. At least that would be theoretically possible.

    > *might* be able to convert a string that long into some kind of
    > 4-digit integer checksum, but you would *never* be able to convert
    > that back into a file path. Nor would it be guaranteed to be unique.


    In fact, if you have 10,001 files it is absolutely guaranteed to have at
    least one duplicate entry.

    --
    D'Arcy J.M. Cain <> | Democracy is three wolves
    http://www.druid.net/darcy/ | and a sheep voting on
    +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
    IM:
    D'Arcy J.M. Cain, Jan 22, 2013
    #7
  8. > No need, to turn the number back to a path anymore, just the path to a number, to identify the specific .html page

    >
    > Can this be done?


    Guaranteed to be unique? Not even remotely possible. Even with a lookup table approach (which defeats your purpose of not storing the path) with 4 digits you're looking at a maximum 10000 unique file paths before your system duplicates numbers. And that's the best-case scenario. Anything else would be worse.

    Not guaranteed to be unique? Easy. Just take then previously given example of pin = int( htmlpage.encode("hex"), 16 ) and mod it to your limit, to make:
    pin = int( htmlpage.encode("hex"), 16 ) % 10000
    It'll give you your number, but there are no guarantees of uniqueness. You're looking at more blind random luck using that.
    Leonard, Arah, Jan 22, 2013
    #8
  9. Τη ΤÏίτη, 22 ΙανουαÏίου 2013 7:24:26 μ.μ. UTC+2, οχÏήστης Leonard, Arah έγÏαψε:
    > > No need, to turn the number back to a path anymore, just the path to a number, to identify the specific .html page

    >
    > >

    >
    > > Can this be done?

    >
    >
    >
    > Guaranteed to be unique? Not even remotely possible. Even with a lookuptable approach (which defeats your purpose of not storing the path) with 4digits you're looking at a maximum 10000 unique file paths before your system duplicates numbers. And that's the best-case scenario. Anything else would be worse.
    >
    >
    >
    > Not guaranteed to be unique? Easy. Just take then previously given example of pin = int( htmlpage.encode("hex"), 16 ) and mod it to your limit, to make:
    >
    > pin = int( htmlpage.encode("hex"), 16 ) % 10000
    >
    > It'll give you your number, but there are no guarantees of uniqueness. You're looking at more blind random luck using that.


    Finally!!!!!! THANK YOU VERY MUCH!!! THIS IS WHAT I WAS LOOKING FOR!!!

    NOW, if you please explain it to me from the innermost parenthesis please, because i do want to understand it!!!

    And since i'am sure it works, and i just used it on http://superhost.gr
    please view my domain and help me understand why its producing errors for me.
    Your 1-line code surely works but somethings not letting my webpage load normally.

    Please take a look....
    Ferrous Cranus, Jan 22, 2013
    #9
  10. Τη ΤÏίτη, 22 ΙανουαÏίου 2013 7:24:26 μ.μ. UTC+2, οχÏήστης Leonard, Arah έγÏαψε:
    > > No need, to turn the number back to a path anymore, just the path to a number, to identify the specific .html page

    >
    > >

    >
    > > Can this be done?

    >
    >
    >
    > Guaranteed to be unique? Not even remotely possible. Even with a lookuptable approach (which defeats your purpose of not storing the path) with 4digits you're looking at a maximum 10000 unique file paths before your system duplicates numbers. And that's the best-case scenario. Anything else would be worse.
    >
    >
    >
    > Not guaranteed to be unique? Easy. Just take then previously given example of pin = int( htmlpage.encode("hex"), 16 ) and mod it to your limit, to make:
    >
    > pin = int( htmlpage.encode("hex"), 16 ) % 10000
    >
    > It'll give you your number, but there are no guarantees of uniqueness. You're looking at more blind random luck using that.


    Finally!!!!!! THANK YOU VERY MUCH!!! THIS IS WHAT I WAS LOOKING FOR!!!

    NOW, if you please explain it to me from the innermost parenthesis please, because i do want to understand it!!!

    And since i'am sure it works, and i just used it on http://superhost.gr
    please view my domain and help me understand why its producing errors for me.
    Your 1-line code surely works but somethings not letting my webpage load normally.

    Please take a look....
    Ferrous Cranus, Jan 22, 2013
    #10
  11. Ferrous Cranus

    John Gordon Guest

    Re: Converting a string to a number by using INT (no hash method)

    In <> Ferrous Cranus <> writes:

    > > pin int( htmlpage.encode("hex"), 16 ) % 10000
    > >
    > > It'll give you your number, but there are no guarantees of uniqueness.

    > You're looking at more blind random luck using that.


    > Finally!!!!!! THANK YOU VERY MUCH!!! THIS IS WHAT I WAS LOOKING FOR!!!


    No it isn't; you said you wanted a unique 4-digit number. This method
    can return the same 4-digit number for lots of different file paths.

    > NOW, if you please explain it to me from the innermost parenthesis please,
    > because i do want to understand it!!!


    1. Transform the html path string into a (large) hexadecimal number
    using the encode() function.

    2. Convert the hexadecimal number into a decimal integer using the
    int() function.

    3. Shrink the integer into the range 0-9999 by using the % operator.
    John Gordon, Jan 22, 2013
    #11
  12. Τη ΤÏίτη, 22 ΙανουαÏίου 2013 7:24:26 μ.μ. UTC+2, οχÏήστης Leonard, Arah έγÏαψε:
    > > No need, to turn the number back to a path anymore, just the path to a number, to identify the specific .html page

    >
    > >

    >
    > > Can this be done?

    >
    >
    >
    > Guaranteed to be unique? Not even remotely possible. Even with a lookuptable approach (which defeats your purpose of not storing the path) with 4digits you're looking at a maximum 10000 unique file paths before your system duplicates numbers. And that's the best-case scenario. Anything else would be worse.
    >
    >
    >
    > Not guaranteed to be unique? Easy. Just take then previously given example of pin = int( htmlpage.encode("hex"), 16 ) and mod it to your limit, to make:
    >
    > pin = int( htmlpage.encode("hex"), 16 ) % 10000
    >
    > It'll give you your number, but there are no guarantees of uniqueness. You're looking at more blind random luck using that.


    ==============================================
    pin = int( htmlpage.encode("hex"), 16 ) % 10000
    ==============================================

    Can you please explain the differences to what you have posted opposed to this perl coding?

    ==============================================
    foreach my $ltr(@ltrs){
    $hash = ( $hash + ord($ltr)) %10000;
    ==============================================

    I want to understand this and see it implemented in Python.
    Ferrous Cranus, Jan 22, 2013
    #12
  13. Τη ΤÏίτη, 22 ΙανουαÏίου 2013 7:24:26 μ.μ. UTC+2, οχÏήστης Leonard, Arah έγÏαψε:
    > > No need, to turn the number back to a path anymore, just the path to a number, to identify the specific .html page

    >
    > >

    >
    > > Can this be done?

    >
    >
    >
    > Guaranteed to be unique? Not even remotely possible. Even with a lookuptable approach (which defeats your purpose of not storing the path) with 4digits you're looking at a maximum 10000 unique file paths before your system duplicates numbers. And that's the best-case scenario. Anything else would be worse.
    >
    >
    >
    > Not guaranteed to be unique? Easy. Just take then previously given example of pin = int( htmlpage.encode("hex"), 16 ) and mod it to your limit, to make:
    >
    > pin = int( htmlpage.encode("hex"), 16 ) % 10000
    >
    > It'll give you your number, but there are no guarantees of uniqueness. You're looking at more blind random luck using that.


    ==============================================
    pin = int( htmlpage.encode("hex"), 16 ) % 10000
    ==============================================

    Can you please explain the differences to what you have posted opposed to this perl coding?

    ==============================================
    foreach my $ltr(@ltrs){
    $hash = ( $hash + ord($ltr)) %10000;
    ==============================================

    I want to understand this and see it implemented in Python.
    Ferrous Cranus, Jan 22, 2013
    #13
  14. On 01/22/2013 11:37 AM, Ferrous Cranus wrote:
    > ============================================== pin = int(
    > htmlpage.encode("hex"), 16 ) % 10000
    > ==============================================
    >
    > Can you please explain the differences to what you have posted
    > opposed to this perl coding?
    >
    > ============================================== foreach my
    > $ltr(@ltrs){ $hash = ( $hash + ord($ltr)) %10000;
    > ==============================================
    >
    > I want to understand this and see it implemented in Python.


    It isn't quite the thing. The perl code is merely a checksum of the
    ascii value of the characters in the file name, that is then chopped
    down to a number < 10000. The Python code is taking the ascii value of
    each character in the file name, converting it to a hexadecimal pair of
    digits, stringing them all out into a long string, then converting that
    to a number using the hexadecimal number parser. This results in a
    *very* large number, 8-bits per letter in the original file name, and
    then chops that down to 10000. Technically neither method is a hash and
    neither will generate unique numbers.

    Here's the python algorithm used on a short word:
    'hello' => '68656c6c6f' (h = 0x68', e=0x65', 0x6c', 0=0x6f)
    => 0x68656c6c6f => 448378203247
    mod that with 10000 and you get 3247

    If you would simply run the python interpreter and try these things out
    you could see how and why they work or not work. What is stopping you
    from doing this?
    Michael Torrie, Jan 22, 2013
    #14
  15. Ferrous Cranus

    Dave Angel Guest

    On 01/22/2013 01:37 PM, Ferrous Cranus wrote:
    >
    >> <snip>
    >>

    >
    > ==============================================
    > pin = int( htmlpage.encode("hex"), 16 ) % 10000
    > ==============================================
    >
    > Can you please explain the differences to what you have posted opposed to this perl coding?
    >
    > ==============================================
    > foreach my $ltr(@ltrs){
    > $hash = ( $hash + ord($ltr)) %10000;
    > ==============================================
    >
    > I want to understand this and see it implemented in Python.
    >


    The perl code will produce the same hash for "abc.html" as for
    "bca.html" That's probably one reason Leonard didn't try to
    transliterate the buggy code.

    In any case, the likelihood of a hash collision for any non-trivial
    website is substantial. As I said elsewhere, if you hash 100 files you
    have about a 40% chance of a collision.

    If you hash 220 files, the likelihood is about 90%

    --
    DaveA
    Dave Angel, Jan 22, 2013
    #15
  16. Τη ΤÏίτη, 22 ΙανουαÏίου 2013 9:02:48 μ.μ. UTC+2, οχÏήστης Michael Torrie έγÏαψε:
    > On 01/22/2013 11:37 AM, Ferrous Cranus wrote:
    >
    > > ============================================== pin = int(

    >
    > > htmlpage.encode("hex"), 16 ) % 10000

    >
    > > ==============================================

    >
    > >

    >
    > > Can you please explain the differences to what you have posted

    >
    > > opposed to this perl coding?

    >
    > >

    >
    > > ============================================== foreach my

    >
    > > $ltr(@ltrs){ $hash = ( $hash + ord($ltr)) %10000;

    >
    > > ==============================================

    >
    > >

    >
    > > I want to understand this and see it implemented in Python.

    >
    >
    >
    > It isn't quite the thing. The perl code is merely a checksum of the
    >
    > ascii value of the characters in the file name, that is then chopped
    >
    > down to a number < 10000. The Python code is taking the ascii value of
    >
    > each character in the file name, converting it to a hexadecimal pair of
    >
    > digits, stringing them all out into a long string, then converting that
    >
    > to a number using the hexadecimal number parser. This results in a
    >
    > *very* large number, 8-bits per letter in the original file name, and
    >
    > then chops that down to 10000. Technically neither method is a hash and
    >
    > neither will generate unique numbers.
    >
    >
    >
    > Here's the python algorithm used on a short word:
    >
    > 'hello' => '68656c6c6f' (h = 0x68', e=0x65', 0x6c', 0=0x6f)
    >
    > => 0x68656c6c6f => 448378203247
    >
    > mod that with 10000 and you get 3247
    >
    >
    >
    > If you would simply run the python interpreter and try these things out
    >
    > you could see how and why they work or not work. What is stopping you
    >
    > from doing this?



    May i sent you my code by mail so for you see whats wrong and http://superhost.gr produces error?<br><br>

    1. this is not a script that iam being paid for.
    2, this is not a class assignemnt

    I just want to use that method of gettign this to work.
    Ferrous Cranus, Jan 22, 2013
    #16
  17. Τη ΤÏίτη, 22 ΙανουαÏίου 2013 9:02:48 μ.μ. UTC+2, οχÏήστης Michael Torrie έγÏαψε:
    > On 01/22/2013 11:37 AM, Ferrous Cranus wrote:
    >
    > > ============================================== pin = int(

    >
    > > htmlpage.encode("hex"), 16 ) % 10000

    >
    > > ==============================================

    >
    > >

    >
    > > Can you please explain the differences to what you have posted

    >
    > > opposed to this perl coding?

    >
    > >

    >
    > > ============================================== foreach my

    >
    > > $ltr(@ltrs){ $hash = ( $hash + ord($ltr)) %10000;

    >
    > > ==============================================

    >
    > >

    >
    > > I want to understand this and see it implemented in Python.

    >
    >
    >
    > It isn't quite the thing. The perl code is merely a checksum of the
    >
    > ascii value of the characters in the file name, that is then chopped
    >
    > down to a number < 10000. The Python code is taking the ascii value of
    >
    > each character in the file name, converting it to a hexadecimal pair of
    >
    > digits, stringing them all out into a long string, then converting that
    >
    > to a number using the hexadecimal number parser. This results in a
    >
    > *very* large number, 8-bits per letter in the original file name, and
    >
    > then chops that down to 10000. Technically neither method is a hash and
    >
    > neither will generate unique numbers.
    >
    >
    >
    > Here's the python algorithm used on a short word:
    >
    > 'hello' => '68656c6c6f' (h = 0x68', e=0x65', 0x6c', 0=0x6f)
    >
    > => 0x68656c6c6f => 448378203247
    >
    > mod that with 10000 and you get 3247
    >
    >
    >
    > If you would simply run the python interpreter and try these things out
    >
    > you could see how and why they work or not work. What is stopping you
    >
    > from doing this?



    May i sent you my code by mail so for you see whats wrong and http://superhost.gr produces error?<br><br>

    1. this is not a script that iam being paid for.
    2, this is not a class assignemnt

    I just want to use that method of gettign this to work.
    Ferrous Cranus, Jan 22, 2013
    #17
  18. Ferrous Cranus

    Alan Spence Guest

    On 22 Jan 2013, at 19:28, Ferrous Cranus <> wrote:

    > Τη ΤÏίτη, 22 ΙανουαÏίου 2013 9:02:48 μ.μ. UTC+2, ο χÏήστης Michael Torrie έγÏαψε:
    >> On 01/22/2013 11:37 AM, Ferrous Cranus wrote:
    >>
    >>> ============================================== pin =int(

    >>
    >>> htmlpage.encode("hex"), 16 ) % 10000

    >>
    >>> ==============================================

    >>
    >>>

    >>
    >>> Can you please explain the differences to what you have posted

    >>
    >>> opposed to this perl coding?

    >>
    >>>

    >>
    >>> ============================================== foreach my

    >>
    >>> $ltr(@ltrs){ $hash = ( $hash + ord($ltr)) %10000;

    >>
    >>> ==============================================

    >>
    >>>

    >>
    >>> I want to understand this and see it implemented in Python.

    >>
    >>
    >>
    >> It isn't quite the thing. The perl code is merely a checksum of the
    >>
    >> ascii value of the characters in the file name, that is then chopped
    >>
    >> down to a number < 10000. The Python code is taking the ascii value of
    >>
    >> each character in the file name, converting it to a hexadecimal pair of
    >>
    >> digits, stringing them all out into a long string, then converting that
    >>
    >> to a number using the hexadecimal number parser. This results in a
    >>
    >> *very* large number, 8-bits per letter in the original file name, and
    >>
    >> then chops that down to 10000. Technically neither method is a hash and
    >>
    >> neither will generate unique numbers.
    >>
    >>
    >>
    >> Here's the python algorithm used on a short word:
    >>
    >> 'hello' => '68656c6c6f' (h = 0x68', e=0x65', 0x6c', 0=0x6f)
    >>
    >> => 0x68656c6c6f => 448378203247
    >>
    >> mod that with 10000 and you get 3247
    >>
    >>
    >>
    >> If you would simply run the python interpreter and try these things out
    >>
    >> you could see how and why they work or not work. What is stopping you
    >>
    >> from doing this?

    >
    >
    > May i sent you my code by mail so for you see whats wrong and http://superhost.gr produces error?<br><br>
    >
    > 1. this is not a script that iam being paid for.
    > 2, this is not a class assignemnt
    >
    > I just want to use that method of gettign this to work.
    > --
    > http://mail.python.org/mailman/listinfo/python-list


    All pages, strings and objects map to:

    http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm

    Alan
    Alan Spence, Jan 22, 2013
    #18
  19. > The perl code will produce the same hash for "abc.html" as for "bca.html" That's probably one reason Leonard didn't try to transliterate the buggycode.
    >


    Actually, to give credit where it's due, it wasn't me. I just modified someone else's interesting solution in this thread and added the silly limit of 10000 to it.

    > In any case, the likelihood of a hash collision for any non-trivial website is substantial.
    >


    Exactly. Four digits is hardly enough range for it to be even remotely safe. And even then range isn't really the issue as technically it just improves your odds.

    The results of a modulus operator are still non-unique no matter how many digits are there to work with ... within reason. Statistically anyone who buys a ticket could potentially win the lottery no matter how bad the odds are. ;)

    And now back to the OP, I'm still confused on this four-digit limitation. Why isn't the limitation at least adhering to a bytelength like byte/short/long? Is this database storing a string of characters instead of an actualnumber? (And if so, then why not just block out 255 characters instead of4 to store a whole path? Or at the very least treat 4 characters as 4 bytes to greatly increase the numeric range?)
    Leonard, Arah, Jan 22, 2013
    #19
  20. Ferrous Cranus

    John Gordon Guest

    Re: Converting a string to a number by using INT (no hash method)

    In <> Ferrous Cranus <> writes:

    > May i sent you my code by mail so for you see whats wrong and
    > http://superhost.gr produces error?


    I tried going to that address and got some error output. I noticed this
    in the error dump:

    186 if cursor.rowcount == 0:
    187 cursor.execute( '''INSERT INTO visitors(pin, host
    , hits, useros, browser, date) VALUES(%s, %s, %s, %s, %s)''', (pin, hos
    t, 1, useros, browser, date) )

    The INSERT statement gives six column names but only five placeholders (%s)
    in the VALUES clause.

    Perhaps that's the problem?

    --
    John Gordon A is for Amy, who fell down the stairs
    B is for Basil, assaulted by bears
    -- Edward Gorey, "The Gashlycrumb Tinies"
    John Gordon, Jan 22, 2013
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schnoffos
    Replies:
    2
    Views:
    1,209
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,629
    Old Wolf
    Jan 20, 2004
  3. Replies:
    6
    Views:
    1,518
    Richard Tobin
    Mar 19, 2009
  4. rp
    Replies:
    1
    Views:
    517
    red floyd
    Nov 10, 2011
  5. Ferrous Cranus
    Replies:
    7
    Views:
    178
    Ferrous Cranus
    Jan 23, 2013
Loading...

Share This Page