X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/5de79e20f1413a24f3339917176241f3e2681c3d..bd46dec63beb7414ce26ec0517c06bf79f676b6d:/client/lualibs/utils.lua diff --git a/client/lualibs/utils.lua b/client/lualibs/utils.lua index 698017d9..39f8bca2 100644 --- a/client/lualibs/utils.lua +++ b/client/lualibs/utils.lua @@ -75,13 +75,27 @@ local Utils = 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) + return utils.ConvertAsciiToHex( + core.iso14443b_crc(s) + ) end return nil end, + ------------ CRC-8 Legic checksums + -- Takes a hex string and calculates a crc8 + Crc8Legic = 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 asc = utils.ConvertHexToAscii(s) + local hash = core.crc8legic(asc) + return hash + end + return nil + end, + ------------ CRC-16 ccitt checksums -- Takes a hex string and calculates a crc16 Crc16 = function(s) @@ -96,6 +110,7 @@ local Utils = return nil end, + ------------ CRC-64 ecma checksums -- Takes a hex string and calculates a crc64 ecma Crc64 = function(s) @@ -286,6 +301,15 @@ local Utils = return n end, + -- a simple implementation of a sleep command. Thanks to Mosci + -- takes number of seconds to sleep + Sleep = function(n) + local clock = os.clock + local t0 = clock() + while clock() - t0 <= n do end + return nil + end, + -- function convertStringToBytes(str) -- local bytes = {} -- local strLength = string.len(str)