Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP bin2hex? issue, not quite sure.

    Hey everyone,

    I have a bit of a problem, i'm trying to fix a problem on a tiny torrent site i run for my music buddies so we can swap stuff back and forth easily. So basically whats happening is the info hash from the announce url, is too long it has an extra character, and i don't know why, this happens on only some torrents.

    After setting $info_hash from the GET variables, i run this:

    Code:
    $info_hash = bin2hex($info_hash);
    Now because of the extra character in the binary form of the info hash it makes a 42 character info hash, and not 40, so anyone have any ideas?

    Any help is greatly appreciated.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    How are you populating the $_GET number? Chances are, its not in a binary format and its interpreting it as a string (and therefore an integer). Effectively, if you don't have it packed as actual binary, the bin2hex is probably not what you want.
    Regardless, you are limited to 64bits on a 64bit machine and a 64bit PHP build. x86 will of course limit you to 32 bits, and one is required for twos bit, so you can have 31. I would suggest you don't exceed the 31, and since it'll need to be interpreted as an integer, that would give you at the most 2^31-1 or a range of (-21478648, 2147483647) as your maximum range. You must stay in there to use mathematical functions and work with any build of PHP.
    After that, you can use dechex or base_convert to change it to hex.

    If you cannot adjust the numbers you need to work with, and you are not on a 64-bit OS, you can try to use the bcmath library in combination with manual binary to hex conversion. I glanced at this and it seems not too bad for how to calculate manually: http://forum.codecall.net/topic/3626...he-manual-way/
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,922
    Thanks
    15
    Thanked 229 Times in 229 Posts
    Now normally such a hash it just a string of hex characters, so I'm guessing that the extra 2 characters are related to the sign. And presumably the hash is just of the file string, not including the filename. I don't see any advantage of the bin2hex at all, the hash is there to make sure everyone is exchanging the same file, and that the file is complete.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #4
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes the bin2hex function changes the binary info hash into the hex based one that all torrent trackers use, i tried finding my own function or creating one for converting it to hex manually instead of using bin2hex.

    Also i should point out the torrent site is based on TBDev if that helps anyone at all.

  • #5
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,922
    Thanks
    15
    Thanked 229 Times in 229 Posts
    So I'm getting it backwards, you're trying to go to hex, maybe find out where they are doing the binary hash and just substitute a regular hex hash function. But how to persuade all the clients to use the same function ? There may be a setting where you can choose different hashes.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #6
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I thought about that but something else has to be going on, because on the old server before it crashed and died everything worked never had any errors but as soon as i moved the site over these errors started happening, and all the proper deps are installed i checked.

    So i don't think its an issue with the bin2hex function because it works flawlessly on another server i put the site on.

    But after comparing packages and config files and everything, its all perfectly the same, version numbers and all.

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Build architecture as well? Check both the OS and PHP builds.
    I don't know the actual problem you have since there is no useful example, but if I had to guess its an invalid number as a result of a x86 compared to an old x64.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #8
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Same OS but the php version is newer 5.4 instead of 5.3, think that could be causing it?

  • #9
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My mistake, reverse that, the new server has the older version, the older server had the new version of php.

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Shouldn't make a difference.
    What is the data you are working with. In -> out and expected results? I cannot see what the problem here is, so I cannot verify if the issue even has anything to do with the bit length available.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #11
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alright, it turns out it was the php version that was causing the problem, no idea why but it was, anyway upgrading to 5.4 fixed everything that was wrong, so thanks for the idea!


  •  

    Posting Permissions

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