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

24
LINES

< > BotCompany Repo | #415 // Rough-Hash Function

Lua code

get("#356") -- num2hex
get("#348") -- rgb functions

function roughHashImage(img)
  local hash = 0
  local w, h = img.width, img.height
  
  for y = 0, h-1 do
    for x = 0, w-1 do
      local pix = img.getInt(x, y)
      local b = math.floor(bright(rgb(pix))*25+0.5)
      local p = b
      local scale = bit32.band(y*w+x, 0xFFFF)+1
      local arg = ((p+1)*scale*7) % 1234567
      hash = bit32.bxor(hash, arg)
      --[[if x < 10 then
        print("scale", scale, "pix", pix, "p", p, "arg", arg, "hash", hash)
      end]]
    end
    --print("y", y, "hash", hash)
  end
  
  return num2hex(hash, 8)
end

Author comment

Began life as a copy of #380

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

Comments [hide]

ID Author/Program Comment Date
965 #1000604 (pitcher) 2015-08-20 15:28:24
964 #1000610 (pitcher) 2015-08-18 00:07:07

add comment

Snippet ID: #415
Snippet name: Rough-Hash Function
Eternal ID of this version: #415/1
Text MD5: 7e158c2267faa430c6f33a04342096ef
Author: stefan
Category: hash functions
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-02-06 13:46:44
Source code size: 629 bytes / 24 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 978 / 164
Referenced in: #416 - Grid + Floodfill with rough hashes
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)