In case anyone is interested, here is my solution to the problem:
Code:
import "Turbine";
local print = Turbine.Shell.WriteLine;
local function encodeHiddenString(s)
if s:len()%8 ~= 0 then error("string length must be divisible by 8") end
local bytes = {};
for i=1, s:len() do
bytes[i] = string.format("%X", s:byte(i));
if bytes[i]:len() < 2 then bytes[i] = "0"..bytes[i] end
end
local selectBegin, selectEnd = "<Select:IID:0x", "><\Select>";
local result, eightBytes = "", "";
local j = 1;
repeat
eightBytes = "";
for i=j, j+7 do
eightBytes = eightBytes..bytes[i];
end
result = result..selectBegin..eightBytes..selectEnd;
j = j+8;
until j > #bytes
return result
end
local function decodeHiddenString(s)
local result = "";
local byteString = "";
for bytes in s:gmatch("<Select:IID:0x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x") do
byteString = byteString..bytes:sub(15, 30);
end
for byte in byteString:gmatch('%x%x') do
local char = string.char(tonumber("0x"..byte));
result = result..char;
end
return result;
end
-- Demo of encoding:
local hiddenMessage = "This is a hidden message";
print("Hello World!"..encodeHiddenString(hiddenMessage));
-- Demo of decoding:
local messageWithHiddenString = "Hello World!<Select:IID:0x5468697320697320><\Select><Select:IID:0x612068696464656E><\Select><Select:IID:0x206D657373616765><\Select>";
print(decodeHiddenString(messageWithHiddenString));