Changes between Version 36 and Version 37 of HashSourceCodes


Ignore:
Timestamp:
Apr 28, 2012, 1:09:53 AM (12 years ago)
Author:
guest
Comment:

Add Lua version

Legend:

Unmodified
Added
Removed
Modified
  • HashSourceCodes

    v36 v37  
    457457}}}
    458458
     459
     460== Lua ==
     461{{{
     462-- will produce a correct hash regardless of architecture (big vs little endian)
     463local function movieHash(fileName)
     464        local fil = io.open(fileName, "rb")
     465        local lo,hi=0,0
     466        for i=1,8192 do
     467                local a,b,c,d = fil:read(4):byte(1,4)
     468                lo = lo + a + b*256 + c*65536 + d*16777216
     469                a,b,c,d = fil:read(4):byte(1,4)
     470                hi = hi + a + b*256 + c*65536 + d*16777216
     471                while lo>=4294967296 do
     472                        lo = lo-4294967296
     473                        hi = hi+1
     474                end
     475                while hi>=4294967296 do
     476                        hi = hi-4294967296
     477                end
     478        end
     479        local size = fil:seek("end", -65536) + 65536
     480        for i=1,8192 do
     481                local a,b,c,d = fil:read(4):byte(1,4)
     482                lo = lo + a + b*256 + c*65536 + d*16777216
     483                a,b,c,d = fil:read(4):byte(1,4)
     484                hi = hi + a + b*256 + c*65536 + d*16777216
     485                while lo>=4294967296 do
     486                        lo = lo-4294967296
     487                        hi = hi+1
     488                end
     489                while hi>=4294967296 do
     490                        hi = hi-4294967296
     491                end
     492        end
     493        lo = lo + size
     494                while lo>=4294967296 do
     495                        lo = lo-4294967296
     496                        hi = hi+1
     497                end
     498                while hi>=4294967296 do
     499                        hi = hi-4294967296
     500                end
     501        fil:close()
     502        return string.format("%08x%08x", hi,lo), size
     503end
     504
     505print("breakdance.avi:")
     506print(movieHash("breakdance.avi"))
     507print("8e245d9679d31e12 <- should be")
     508print("")
     509print("dummy.rar:")
     510print(movieHash("dummy.rar"))
     511print("61f7751fc2a72bfb <- should be according to wiki")
     512print("2a527d74d45f5b1b <- what other hash tools actually report")
     513}}}
     514
     515
    459516== !RealBasic ==
    460517Combined routine that will calculate a fast hash for videofiles over 65K and a normal md5 for subtitles