Randomize table of byte values w/ key to unrandomize

I am trying to randomize a table of byte values. However, I need to be able to unrandomize them using a key that is unique to the randomized table. Currently, I am doing the following:

local key = {}
local randomized = {}

for i = 1, #bytes do
	local random = math.random(1,#bytes * #bytes)
	table.insert(key,random)
	table.insert(randomized,random,bytes[i])
end

This works fine because my test string (which is converted into a table of bytes) is simply “Hello world!”. However, with longer strings the key would keep getting longer and longer, and I would like to keep the key at or under 26 characters.

Any help is greatly appreciated.

You need a derrived key. The key you want should be a constant length and be used to create a derrived key of variable length. There are lots of algorithms out there to do this specifically, if you want one that just works and is easy to understand, use RC4.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.