FIX: I think the dumping of data is correct now in tnp3.lua. MD5 string vs bytearrays in lua are tricky

ADD: utils.lua some functions to convert between ascii, bytes and strings.
This commit is contained in:
iceman1001 2014-11-09 19:29:47 +01:00
commit cd5767d43d
2 changed files with 46 additions and 25 deletions

View file

@ -46,21 +46,46 @@ local Utils =
end,
---
-- Convert Byte array to string of hex
ConvertBytes2String = function(bytes)
local s = {}
ConvertBytes2HexString = function(bytes)
if #bytes == 0 then
return ''
end
local s={}
for i = 1, #(bytes) do
s[i] = string.format("%02X",bytes[i])
end
return table.concat(s)
end,
ConvertStringToBytes = function(s)
-- Convert byte array to string with ascii
ConvertBytesToAsciiString = function(bytes)
if #bytes == 0 then
return ''
end
local s={}
for i = 1, #(bytes) do
s[i] = string.char(bytes[i])
end
return table.concat(s)
end,
ConvertHexStringToBytes = function(s)
local t={}
if s == nil then return t end
if #s == 0 then return t end
for k in s:gmatch"(%x%x)" do
table.insert(t,tonumber(k,16))
end
return t
end,
ConvertAsciiStringToBytes = function(s)
local t={}
if s == nil then return t end
if #s == 0 then return t end
for k in s:gmatch"(.)" do
table.insert(t, string.byte(k))
end
return t
end,
-- function convertStringToBytes(str)
-- local bytes = {}