MOD:: reverse back changes to 14443b.c

ADD: the hid-flasher/usb_cmd.h  wasn't up to date with how it's other file /common/usb_cmd.h looks like.
ADD: utils.lua  14443v crc inside LUA.
ADD: utils.lua  ConvertAsciiToHex method and minor adjustments checks.
This commit is contained in:
iceman1001 2015-07-28 21:33:09 +02:00
commit 5de79e20f1
6 changed files with 123 additions and 25 deletions

View file

@ -69,6 +69,18 @@ local Utils =
return outResults
end,
----ISO14443-B CRC
Crc14b = function(s)
if s == nil then return nil end
if #s == 0 then return nil end
if type(s) == 'string' then
local utils = require('utils')
local ascii = utils.ConvertHexToAscii(s)
local hashed = core.iso14443b_crc(ascii)
return utils.ConvertAsciiToHex(hashed)
end
return nil
end,
------------ CRC-16 ccitt checksums
-- Takes a hex string and calculates a crc16
@ -181,20 +193,18 @@ local Utils =
---
-- Convert Byte array to string of hex
ConvertBytesToHex = function(bytes)
if #bytes == 0 then
return ''
end
if bytes == nil then return '' end
if #bytes == 0 then return '' end
local s={}
for i = 1, #(bytes) do
for i = 1, #bytes do
s[i] = string.format("%02X",bytes[i])
end
return table.concat(s)
end,
-- Convert byte array to string with ascii
ConvertBytesToAscii = function(bytes)
if #bytes == 0 then
return ''
end
if bytes == nil then return '' end
if #bytes == 0 then return '' end
local s={}
for i = 1, #(bytes) do
s[i] = string.char(bytes[i])
@ -233,13 +243,23 @@ local Utils =
end,
ConvertHexToAscii = function(s)
if s == nil then return '' end
if #s == 0 then return '' end
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, string.char(tonumber(k,16)))
end
return table.concat(t)
return table.concat(t)
end,
ConvertAsciiToHex = function(s)
if s == nil then return '' end
if #s == 0 then return '' end
local t={}
for k in s:gmatch"(.)" do
table.insert(t, string.format("%02X", string.byte(k)))
end
return table.concat(t)
end,
Chars2num = function(s)