]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/lualibs/utils.lua
MOD:: reverse back changes to 14443b.c
[proxmark3-svn] / client / lualibs / utils.lua
index da1797582132a1781831cfbb0e848cef27f4e91d..698017d923d28de50a5baa044d7eb51510b1699a 100644 (file)
@@ -69,6 +69,18 @@ local Utils =
                return outResults\r
        end,\r
        \r
+       ----ISO14443-B CRC\r
+       Crc14b = function(s)\r
+               if s == nil then return nil end\r
+               if #s == 0 then return nil end\r
+               if  type(s) == 'string' then\r
+                       local utils = require('utils')\r
+                       local ascii = utils.ConvertHexToAscii(s)\r
+                       local hashed = core.iso14443b_crc(ascii)\r
+                       return utils.ConvertAsciiToHex(hashed)\r
+               end\r
+               return nil              \r
+       end,\r
        \r
        ------------ CRC-16 ccitt checksums\r
        -- Takes a hex string and calculates a crc16\r
@@ -181,20 +193,18 @@ local Utils =
        ---\r
        -- Convert Byte array to string of hex\r
        ConvertBytesToHex = function(bytes)\r
-               if #bytes == 0 then\r
-                       return ''\r
-               end\r
+               if bytes == nil then return '' end\r
+               if #bytes == 0 then return '' end\r
                local s={}\r
-               for i = 1, #(bytes) do\r
+               for i = 1, #bytes do\r
                        s[i] = string.format("%02X",bytes[i]) \r
                end\r
                return table.concat(s)\r
        end,    \r
        -- Convert byte array to string with ascii\r
     ConvertBytesToAscii = function(bytes)\r
-               if #bytes == 0 then\r
-                       return ''\r
-               end\r
+               if bytes == nil then return '' end\r
+               if #bytes == 0 then return '' end\r
                local s={}\r
                for i = 1, #(bytes) do\r
                        s[i] = string.char(bytes[i]) \r
@@ -233,13 +243,23 @@ local Utils =
        end,\r
        \r
        ConvertHexToAscii = function(s)\r
+               if s == nil then return '' end\r
+               if #s == 0 then return '' end\r
                local t={}\r
-               if s == nil then return t end\r
-               if #s == 0 then return t end\r
                for k in s:gmatch"(%x%x)" do\r
                        table.insert(t, string.char(tonumber(k,16)))\r
                end\r
-               return  table.concat(t) \r
+               return table.concat(t)  \r
+       end,\r
+       \r
+       ConvertAsciiToHex = function(s)         \r
+               if s == nil then return '' end\r
+               if #s == 0 then return '' end\r
+               local t={}\r
+               for k in s:gmatch"(.)" do\r
+                       table.insert(t, string.format("%02X", string.byte(k)))\r
+               end\r
+               return table.concat(t)\r
        end,\r
        \r
        Chars2num = function(s)\r
Impressum, Datenschutz