Hash Source Code : Visual Basic 6 (VB6) Code

For developers and developing site - suggestions, coding problems, API questions, new applications...
Forum rules
Under no circumstances is spamming or advertising of any kind allowed. Do not post any abusive, obscene, vulgar, slanderous, hateful, threatening, sexually-orientated or any other material that may violate others security. Profanity or any kind of insolent behavior to other members (regardless of rank) will not be tolerated. Remember, what you don’t find offensive can be offensive to other members. Please treat each other with the kind of reverence you’d expect from other members.
Failure to comply with any of the above will result in users being banned without notice. If any further details are needed, contact: “The team” using the link at the bottom of the forum page. Thank you.

Hash Source Code : Visual Basic 6 (VB6) Code

Postby sarathkcm » Thu Aug 09, 2012 3:46 pm

I didn't see any VB6 implementation of the code to calculate hash code for video files. I wrote one.

It works well for the breakdance.avi file, and I tried few movie files and succeeded in identifying them with the produced hash.

It didn't worked for the dummy.rar file provided, It produces a different hashe than the one provided in the website...

But the C code given in the website also fails to produce hash code for dummy.rar file too...

And to my relief The C code and my vb code produces the same hash for the dummy.rar file, So i'm posting the code here anyway...


There may be better implementations.... post them as comments please....


Code: Select all
Function find_Hash(path As String) As String
On Error GoTo ErrM:
Dim fl As Long
Dim fsize As Variant
Dim byteArray(7) As Byte
Dim intArray(7) As Long
Dim Hash As String

fl = FreeFile()

For j = 0 To 7
    intArray(j) = 0
Next


fsize = FileLen(path)

Open path For Binary As #fl
Seek #fl, 1
For i = 0 To 8191
Get #fl, , byteArray
    For j = 0 To 7
    intArray(j) = intArray(j) + byteArray(j)
    Next
Next

If (fsize - 65536 + 1) > 0 Then
Seek #fl, fsize - 65536 + 1
Else
Seek #fl, 1
End If


For i = 0 To 8191
Get #fl, , byteArray
    For j = 0 To 7
    intArray(j) = intArray(j) + byteArray(j)
    Next
Next
Close #fl


For i = 0 To 7

intArray(i) = intArray(i) + fsize Mod 256
fsize = fsize \ 256

Next




For i = 0 To 6

intArray(i + 1) = intArray(i + 1) + (intArray(i) \ 256)
Next


For i = 0 To 7

byteArray(i) = CByte(intArray(i) Mod 256)

Next

Hash = ""
For i = 7 To 0 Step -1




If Len(Hex(byteArray(i))) < 2 Then

Hash = Hash & "0" & Hex(byteArray(i))
Else
Hash = Hash & Hex(byteArray(i))
End If

Next
Hash = LCase(Hash)
find_Hash = Hash
Exit Function

ErrM:

find_Hash = 0


End Function
sarathkcm
 
Posts: 28
Joined: Thu Aug 09, 2012 3:11 pm

Re: Hash Source Code : Visual Basic 6 (VB6) Code

Postby oss » Sat Aug 11, 2012 5:04 am

all sources of moviehashes should provide same results, I didnt test them myself. If you will find some implementation which doesn't, I can not post it to trac for now - or with the comment. We should make sources to make 100% identical results, otherwise it will be mess.
User avatar
oss
Site Admin
 
Posts: 2208
Joined: Sat Feb 25, 2006 11:26 pm

Re: Hash Source Code : Visual Basic 6 (VB6) Code

Postby sarathkcm » Sat Aug 11, 2012 10:58 am

as far as I tested, this code works well, and my code was able to fetch movie details through opensubtitles api most time correctly. with some movies there were problems, but that was not because of wrong hash- i manually searched those hashes on website and found correct results. As I said, the C code provided in the trac and this code gives identical results for all of the files i've tested.

I have a question: for the RAR file given, shall I find the code of the RAR file or the extracted content of it or something else???
sarathkcm
 
Posts: 28
Joined: Thu Aug 09, 2012 3:11 pm

Re: Hash Source Code : Visual Basic 6 (VB6) Code

Postby sarathkcm » Sat Aug 11, 2012 2:56 pm

oh, there comes error with large files....
sarathkcm
 
Posts: 28
Joined: Thu Aug 09, 2012 3:11 pm

Re: Hash Source Code : Visual Basic 6 (VB6) Code

Postby sarathkcm » Sat Aug 11, 2012 2:56 pm

oh, there comes error with large files....
sarathkcm
 
Posts: 28
Joined: Thu Aug 09, 2012 3:11 pm

Re: Hash Source Code : Visual Basic 6 (VB6) Code

Postby srtpal » Sat Aug 11, 2012 7:21 pm

sarathkcm wrote:I have a question: for the RAR file given, shall I find the code of the RAR file or the extracted content of it or something else???

The extracted video file. In other words, you should get the same hash when you get it from the RAR file and when you get it from the video file after it was extracted from the RAR file. After all, some people will try to upload (or download) the subs using the RAR file and others, perhaps most, will extract the video file from the RAR file and only then download or upload subtitles for it.

The RAR is just a container, the video file contained within is what matters.
srtpal
 
Posts: 59
Joined: Sun Jun 21, 2009 5:28 pm

Re: Hash Source Code : Visual Basic 6 (VB6) Code

Postby sarathkcm » Sat Aug 11, 2012 9:16 pm

@srtpal: Thanks Man, I ran my code on the RAR file, that's why I got a different result....

If anyone's gonna use this code, please note that this will work only for files of size upto 2GB, not a byte more.... If you have a bigger file with >2GB size, you will get a wrong hash....

I'm looking forward to find a better code. VB6 is too old guyz, Its already time that i should learn some newer language...... :( :( :(
sarathkcm
 
Posts: 28
Joined: Thu Aug 09, 2012 3:11 pm


Return to Developing

Who is online

Users browsing this forum: No registered users and 0 guests