return retval\r
end,\r
\r
+ -- input parameter is a string\r
+ -- Swaps the endianess and returns a string, \r
+ -- IE: 'cd7a' -> '7acd' -> 0x7acd\r
+ SwapEndiannessStr = function(s, len)\r
+ if s == nil then return nil end\r
+ if #s == 0 then return '' end\r
+ if type(s) ~= 'string' then return nil end\r
+ \r
+ local retval\r
+ if len == 16 then\r
+ retval = s:sub(3,4)..s:sub(1,2)\r
+ elseif len == 24 then\r
+ retval = s:sub(5,6)..s:sub(3,4)..s:sub(1,2)\r
+ elseif len == 32 then\r
+ retval = s:sub(7,8)..s:sub(5,6)..s:sub(3,4)..s:sub(1,2)\r
+ end\r
+ return retval\r
+ end, \r
------------ CONVERSIONS\r
\r
--\r
local B,K,OUT,I,D=16,"0123456789ABCDEF","",0\r
while IN>0 do\r
I=I+1\r
- IN,D=math.floor(IN/B),math.mod(IN,B)+1\r
+ IN , D = math.floor(IN/B), math.modf(IN,B)+1\r
OUT=string.sub(K,D,D)..OUT\r
end\r
return OUT\r
end\r
local s={}\r
for i = 1, #(bytes) do\r
- s[i] = string.format("%02X",bytes[i]) \r
+ s[i] = string.format("%02X",bytes[i]) \r
end\r
return table.concat(s)\r
end, \r