PHP version of thumbnail hash calculation needed
#1
I'm looking for a bit of help in translating a C# script into a PHP script/function. I am working on a PHP-tool for enhancing my remote XBMC collection for my standalone mediastreamer.

The big problem is, my limited knowledge of C# is making me unable to translate the C# hashscript into a PHP-function.

This is the code according to one of the XBMC-Wikipages. Unfortunately I'm unable to get past the XOR and other math thingies.

Code:
public string Hash(string input)
{
   char[] chars = input.ToCharArray();
   for (int index = 0; index < chars.Length; index++)
   {
       if (chars[index] <= 127)
       {
          chars[index] = System.Char.ToLowerInvariant(chars[index]);
       }
   }
   input = new string(chars);
   uint m_crc = 0xffffffff;
   byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input);
   foreach (byte myByte in bytes)
   {
       m_crc ^= ((uint)(myByte) << 24);
       for (int i = 0; i < 8; i++)
       {
           if ((System.Convert.ToUInt32(m_crc) & 0x80000000) == 0x80000000)
           {
               m_crc = (m_crc << 1) ^ 0x04C11DB7;
           }
           else
           {
               m_crc <<= 1;
           }
       }
   }
   return String.Format("{0:x8}", m_crc);
}

These are two supposed examples of text strings that should work with this code:
* 123456789 returns 0376e6e7
* F:\Videos\Nosferatu.avi returns 2a6ec78d

Hope anyone can help me out with a "translation" to PHP of this C# routine. Thanks in advance Eek
Reply


Messages In This Thread
PHP version of thumbnail hash calculation needed - by Klojum - 2010-11-15, 15:31
[No subject] - by spiff - 2010-11-15, 15:36
[No subject] - by Nick8888 - 2010-11-15, 15:40
[No subject] - by opdenkamp - 2010-11-15, 16:09
[No subject] - by rhormaza - 2011-01-19, 04:54
[No subject] - by MakuraRyu - 2011-02-12, 22:57
[No subject] - by DKreeK - 2011-02-19, 12:12
[No subject] - by narfight - 2011-10-12, 18:55
[No subject] - by tamplan - 2012-01-07, 23:55
[No subject] - by baderj - 2012-02-27, 12:02
Logout Mark Read Team Forum Stats Members Help
PHP version of thumbnail hash calculation needed0