» »

Dump MaCoFaCove kode za hash

Dump MaCoFaCove kode za hash

BluPhenix ::

Pomen:
00 .................................. rezervirano (1 B)
0f95 ................................ video traja 3989 sekund (2 B)
00002bbcc000 ........................ datoteka je dolga 733.790.208 B (6 B)
18d5d8c1747b005aaa2800a18e81de97 .... MD5 hash (16 B)
11 .................................. kontrolni bajt (1 B)


Algoritem:
/// <summary>
/// C# algorithm which computes hash of video file. Computed hash is then used to find matching subtitles.
/// </summary>
/// <param name="filePath">Absolute path to video file.</param>
/// <returns>Computed hash value formated as hexadecimal string (52 characters). Returns null on failure.</returns>
public static string Compute(string filePath)
{
    try
    {
        if (!System.IO.File.Exists(filePath))
        {
            return null;
        }

        List<byte> hash = new List<byte>(26);

        //0: reserved
        hash.Insert(0, 0x0);

        //1-2: video length in seconds
        short runTime = new VideoInfo(filePath).RunTime;
        if (BitConverter.IsLittleEndian)
        {
            hash.InsertRange(1, Invert(BitConverter.GetBytes(runTime)));
        }
        else
        {
            hash.InsertRange(1, BitConverter.GetBytes(runTime));
        }

        //3-8: file length in bytes
        long fileLength = new FileInfo(filePath).Length;
        if (BitConverter.IsLittleEndian)
        {
            hash.InsertRange(3, GetLastBytes(Invert(BitConverter.GetBytes(fileLength)), 6));
        }
        else
        {
            hash.InsertRange(3, GetLastBytes(BitConverter.GetBytes(fileLength), 6));
        }

        //9-24: MD5 hash for first 5 MB of file
        hash.InsertRange(9, ComputeMD5FromFile(filePath, 5 * 1024 * 1024));

        //25: control byte
        int sum = 0;
        for (int i = 0; i < 25; i++)
        {
            sum += hash[i];
        }
        hash.Insert(25, Convert.ToByte(sum % 256));

        //convert to hex string
        StringBuilder sbResult = new StringBuilder();
        for (int i = 0; i < hash.Count; i++)
        {
            sbResult.AppendFormat("{0:x2}", hash[i]);
        }
        return sbResult.ToString();

    }
    catch
    {
        return null;
    }
}
Podpisa ni več, ker so me poskušali asimilirati.


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

[c#] shrani text, tabele, slike

Oddelek: Programiranje
251410 (1016) klemen93
»

[java] Kako v memoriji pretvoriti String objekt v File objekt ? - neka metoda ga zaht

Oddelek: Programiranje
132057 (2057) infiniteLoop
»

[asp.net] simpl image editor

Oddelek: Programiranje
61462 (1267) darkolord
»

branje byte[] iz MS access-ove baze

Oddelek: Programiranje
81781 (1691) BHawk
»

Odpiranje dat.exe v VB

Oddelek: Programiranje
122811 (2604) webblod

Več podobnih tem