2010-11-15, 15:31
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.
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
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