Public Function getHash(Filename As String) As String
Dim hFile As File
Dim fSize As Long
Dim tmpHash As New Long[]
Dim i As Integer
Dim sText As String
Dim tmpShort As New Variant[]
Dim Offset As Long
hFile = Open Filename For Input
hFile.ByteOrder = gb.LittleEndian
fSize = Stat(Filename).Size
tmpHash.Add(fsize And 65535)
tmpHash.Add((Shr(fsize, 16)) And 65535)
tmpHash.Add(0)
tmpHash.Add(0)
For i = 0 To 8191
tmpShort.Clear
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
tmpHash = AddUINT64(tmpHash, tmpShort)
Next
Offset = fSize - 65536
Seek #hFile, IIf(Offset > 0, Offset, 0)
For i = 0 To 8191
tmpShort.Clear
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
tmpHash = AddUINT64(tmpHash, tmpShort)
Next
hFile.Close()
Return LCase(Hex(tmpHash[3]) & Hex(tmpHash[2]) & Hex(tmpHash[1]) & Hex(tmpHash[0]))
End
Private Function AddUINT64(Hash As Variant[], tmpShort As Variant[]) As Variant[]
Dim Result As New Variant[]
Dim Carry As Integer = 0
Dim i As Integer
Result = [0, 0, 0, 0]
For i = 0 To 3
If (Hash[i] + tmpShort[i] + Carry) > 65535 Then
Result[i] = (Hash[i] + tmpShort[i] + Carry) And 65535
Carry = 1
Else
Result[i] = (Hash[i] + tmpShort[i] + Carry)
Carry = 0
Endif
Next
Return Result
End
Dim hFile As File
Dim fSize As Long
Dim tmpHash As New Long[]
Dim i As Integer
Dim sText As String
Dim tmpShort As New Variant[]
Dim Offset As Long
hFile = Open Filename For Input
hFile.ByteOrder = gb.LittleEndian
fSize = Stat(Filename).Size
tmpHash.Add(fsize And 65535)
tmpHash.Add((Shr(fsize, 16)) And 65535)
tmpHash.Add(0)
tmpHash.Add(0)
For i = 0 To 8191
tmpShort.Clear
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
tmpHash = AddUINT64(tmpHash, tmpShort)
Next
Offset = fSize - 65536
Seek #hFile, IIf(Offset > 0, Offset, 0)
For i = 0 To 8191
tmpShort.Clear
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
sText = Read #hFile, 2
tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
tmpHash = AddUINT64(tmpHash, tmpShort)
Next
hFile.Close()
Return LCase(Hex(tmpHash[3]) & Hex(tmpHash[2]) & Hex(tmpHash[1]) & Hex(tmpHash[0]))
End
Private Function AddUINT64(Hash As Variant[], tmpShort As Variant[]) As Variant[]
Dim Result As New Variant[]
Dim Carry As Integer = 0
Dim i As Integer
Result = [0, 0, 0, 0]
For i = 0 To 3
If (Hash[i] + tmpShort[i] + Carry) > 65535 Then
Result[i] = (Hash[i] + tmpShort[i] + Carry) And 65535
Carry = 1
Else
Result[i] = (Hash[i] + tmpShort[i] + Carry)
Carry = 0
Endif
Next
Return Result
End