]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/lualibs/utils.lua
update changelog
[proxmark3-svn] / client / lualibs / utils.lua
index e84f70ada526e99b36b69f5077f5be8208e2c587..c5baa406955d067012d525e9b57c8bf9cc525a42 100644 (file)
@@ -108,6 +108,24 @@ local Utils =
                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
@@ -116,7 +134,7 @@ local Utils =
                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
Impressum, Datenschutz