Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local functions = {}
- functions.xor = function(a, b)
- return (a == b) and 0 or 1
- end
- functions.chop = function(string, interval)
- local components = {}
- while string:len() > 0 do
- local component = (string:len() >= interval) and string:sub(1, interval) or string:sub(1)
- table.insert(components, component)
- string = string:sub(interval + 1)
- end
- return components
- end
- functions.cipher = function(binary, key)
- local components = functions.chop(binary, 256)
- local result = {}
- for component = 1, #components do
- for index = 1, components[component]:len() do
- local currBin = tonumber(components[component]:sub(index, index))
- local currKey = tonumber(key:sub(index, index))
- table.insert(result, functions.xor(currBin, currKey))
- end
- end
- return table.concat(result)
- end
- functions.createKey = function(length)
- math.randomseed(os.time())
- local key = {}
- for index = 1, length do
- local bit = (math.random() < 0.5) and 0 or 1
- table.insert(key, bit)
- end
- return table.concat(key)
- end
- return functions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement