X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/9b989c45b942356410416b10e96bc4ca624e4563..f595de25e95a66b9cf0e31c1925500db0abdae08:/client/lualibs/utils.lua diff --git a/client/lualibs/utils.lua b/client/lualibs/utils.lua index 6b3777db..bff89c5f 100644 --- a/client/lualibs/utils.lua +++ b/client/lualibs/utils.lua @@ -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 = {}