| 459 | |
| 460 | == Lua == |
| 461 | {{{ |
| 462 | -- will produce a correct hash regardless of architecture (big vs little endian) |
| 463 | local 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 |
| 503 | end |
| 504 | |
| 505 | print("breakdance.avi:") |
| 506 | print(movieHash("breakdance.avi")) |
| 507 | print("8e245d9679d31e12 <- should be") |
| 508 | print("") |
| 509 | print("dummy.rar:") |
| 510 | print(movieHash("dummy.rar")) |
| 511 | print("61f7751fc2a72bfb <- should be according to wiki") |
| 512 | print("2a527d74d45f5b1b <- what other hash tools actually report") |
| 513 | }}} |
| 514 | |
| 515 | |