Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

19
LINES

< > BotCompany Repo | #378 // RS Image Hash Function

Lua code

1  
get("#356") -- num2hex
2  
3  
function RSHash(img)
4  
  local b, a, hash = 378551, 63689, 0
5  
  local w, h = img.width, img.height
6  
  
7  
  for y = 0, h-1 do
8  
    for x = 0, w-1 do
9  
      local pix = img.getInt(x, y)
10  
      --hash = (hash * a + pix) % 0x100000000
11  
      --a = (a * b) % 0x100000000
12  
      hash = bit32.band(hash * a + pix, 0xFFFFFFFF)
13  
      a = bit32.band(a * b, 0xFFFFFFFF)
14  
    end
15  
  end
16  
  
17  
  print("rshash: a=", a)
18  
  return num2hex(hash, 8)
19  
end

Author comment

originally from http://www.partow.net/programming/hashfunctions/ - might have different results

test run  test run with input  download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #378
Snippet name: RS Image Hash Function
Eternal ID of this version: #378/1
Text MD5: e6a0e122f12fe2317f4e7d8e916e0754
Author: stefan
Category: hash functions
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-02-01 21:47:53
Source code size: 461 bytes / 19 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 658 / 143
Referenced in: [show references]