Skip to content

Instantly share code, notes, and snippets.

@catwell
Created May 8, 2018 19:33
Show Gist options
  • Save catwell/1e022833ae849180adf58d72245ce8e0 to your computer and use it in GitHub Desktop.
Save catwell/1e022833ae849180adf58d72245ce8e0 to your computer and use it in GitHub Desktop.
-- If you need pure Lua *and* don't need crypto strength.
local function random_keys(n)
local t = {}
return function()
for i = 1, n do t[i] = string.char(math.random(0, 255)) end
return table.concat(t)
end
end
local next_key = random_keys(16)
local key1 = next_key()
local key2 = next_key()
--- ... etc
local function seq_keys(n)
local t = {}
for i = 1, n - 1 do t[i] = 0 end
t[n] = -1
return function()
for i = n, 1, -1 do
if t[i] == 255 then
t[i] = 0
else
t[i] = t[i] + 1
break
end
end
return string.char(table.unpack(t))
end
end
local next_key = seq_keys(16)
local key1 = next_key()
local key2 = next_key()
--- ... etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment