My idea is that the algorithm is fed a url to a video file, and returns the hash. Simple. Problem is, I'm not getting the right value back. According to the page I've linked to, this file should return 8e245d9679d31e12, but I'm getting 00c4fcb4aa6f763e. Here is my C#:
Code: Select all
public static async Task<byte[]> ComputeMovieHash(string filename)
{
long filesize = 0;
//Get File Size
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(filename);
req.Method = "HEAD";
var resp = await req.GetResponseAsync();
filesize = resp.ContentLength;
long lhash = filesize;
//Get first 64K bytes
byte[] firstbytes = new byte[0];
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Range", "bytes=0-65536");
using (HttpResponseMessage response = await client.GetAsync(filename))
{
Debug.WriteLine("getting first bytes (bytes=0-65536)");
firstbytes = await response.Content.ReadAsByteArrayAsync();
}
}
lhash += BitConverter.ToInt64(firstbytes, 0);
//Get last 64K bytes
byte[] lastbytes = new byte[0];
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Range", "bytes=" + (filesize - 65536) + "-" + filesize);
using (HttpResponseMessage response = await client.GetAsync(filename))
{
Debug.WriteLine("getting last bytes (" + "bytes=" + (filesize - 65536) + "-" + filesize + ")");
lastbytes = await response.Content.ReadAsByteArrayAsync();
}
}
lhash += BitConverter.ToInt64(lastbytes, 0);
//Return result
byte[] result = BitConverter.GetBytes(lhash);
Array.Reverse(result);
Debug.WriteLine("RESULT=" + ToHexadecimal(result));
return result;
}