Module:Bytestring

local exports = {};

local ascii_array = " !\"#$%&'*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

function exports.encode(frame) local text = frame.args[1]; local out = ""; for itr = 1, #text do       out = out .. string.format("%02x", text:sub(itr, itr):byte); end; return out; end;

function exports.decode(data) local out = ""; for itr = 1, math.floor((#data) / 2) do       out = out .. ascii(tonumber(data:sub((itr - 1) * 2 + 1, (itr - 1) * 2 + 2), 16)); end; return out; end;

function ascii(value) if value 126 then return "[error:" .. tostring(value) .. "]"   end return ascii_array:sub(value - 31, value - 31) end

return exports;