]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/lualibs/utils.lua
ADD: aes128_encrypt ECB in scripting.c
[proxmark3-svn] / client / lualibs / utils.lua
index f7749ca618be04e3ce25273541e65d17871c798e..7db57f333717584cc4b67c8da8419bd05107f9dd 100644 (file)
@@ -71,8 +71,8 @@ local Utils =
                return outResults\r
        end,\r
        \r
-       ------------ CRC-16 ccitt checksums\r
        \r
+       ------------ CRC-16 ccitt checksums\r
        -- Takes a hex string and calculates a crc16\r
        Crc16 = function(s)\r
                if s == nil then return nil end\r
@@ -85,7 +85,48 @@ local Utils =
                end\r
                return nil\r
        end,\r
+       \r
+       ------------ CRC-64 ecma checksums\r
+       -- Takes a hex string and calculates a crc64 ecma\r
+       Crc64 = 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 asc = utils.ConvertHexToAscii(s)\r
+                       local hash = core.crc64(asc)\r
+                       return hash\r
+               end\r
+               return nil\r
+       end,\r
 \r
+       ------------ SHA1 hash\r
+       -- Takes a string and calculates a SHA1 hash\r
+       Sha1 = 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 asc = utils.ConvertHexToAscii(s)\r
+                       local hash = core.sha1(s)\r
+                       return hash\r
+               end\r
+               return nil\r
+       end,    \r
+       -- Takes a hex string and calculates a SHA1 hash\r
+       Sha1Hex = 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 asc = utils.ConvertHexToAscii(s)\r
+                       local hash = core.sha1(asc)\r
+                       return hash\r
+               end\r
+               return nil\r
+       end,    \r
+\r
+       \r
        -- input parameter is a string\r
        -- Swaps the endianess and returns a number,  \r
        -- IE:  'cd7a' -> '7acd'  -> 0x7acd\r
@@ -171,16 +212,28 @@ local Utils =
                end\r
                return t\r
        end,\r
-       ConvertAsciiToBytes = function(s)\r
-               local t={}\r
+       ConvertAsciiToBytes = function(s, reverse)\r
+               local t = {}\r
                if s == nil then return t end\r
                if #s == 0 then return t end\r
                \r
                for k in s:gmatch"(.)" do\r
                        table.insert(t, string.byte(k))\r
                end\r
-               return t\r
+               \r
+               if not reverse then\r
+                       return t\r
+               end\r
+       \r
+               local rev = {}\r
+               if reverse then\r
+                       for i = #t, 1,-1 do\r
+                               table.insert(rev, t[i] )\r
+                       end\r
+               end\r
+               return rev\r
        end,\r
+       \r
        ConvertHexToAscii = function(s)\r
                local t={}\r
                if s == nil then return t end\r
Impressum, Datenschutz