relax ecdsa_publickey_ng_t, should help MacOS compilation
[RRG-proxmark3.git] / client / luascripts / data_hex_crc.lua
bloba970eaf93c618415faaf3f38496355320ab9f3e6
1 local getopt = require('getopt')
2 local utils = require('utils')
3 local ansicolors = require('ansicolors')
5 copyright = ''
6 author = 'Iceman'
7 version = 'v1.0.2'
8 desc = [[
9 This script calculates many checksums (CRC) over the provided hex input.
11 example = [[
12 script run data_hex_crc -b 010203040506070809
13 script run data_hex_crc -b 010203040506070809 -w 16
15 usage = [[
16 script run data_hex_crc [-b <hex bytes] [-w <width>]
18 arguments = [[
19 -b data in hex
20 -w bitwidth of the CRC family of algorithm. <optional> defaults to all known CRC presets.
22 ---
23 -- A debug printout-function
24 local function dbg(args)
25 if not DEBUG then return end
26 if type(args) == 'table' then
27 local i = 1
28 while args[i] do
29 dbg(args[i])
30 i = i+1
31 end
32 else
33 print('###', args)
34 end
35 end
36 ---
37 -- This is only meant to be used when errors occur
38 local function oops(err)
39 print('ERROR:', err)
40 core.clearCommandBuffer()
41 return nil, err
42 end
43 ---
44 -- Usage help
45 local function help()
46 print(copyright)
47 print(author)
48 print(version)
49 print(desc)
50 print(ansicolors.cyan..'Usage'..ansicolors.reset)
51 print(usage)
52 print(ansicolors.cyan..'Arguments'..ansicolors.reset)
53 print(arguments)
54 print(ansicolors.cyan..'Example usage'..ansicolors.reset)
55 print(example)
56 end
57 ---
58 -- The main entry point
59 function main(args)
61 local data
62 local width = 0
64 -- Read the parameters
65 for o, a in getopt.getopt(args, 'hb:w:') do
66 if o == 'h' then return help() end
67 if o == 'b' then data = a end
68 if o == 'w' then width = a end
69 end
71 data = data or '01020304'
72 width = width or 0
74 print( string.rep('-',60) )
75 print('Bit width of CRC | '..width)
76 print('Bytes | '..data)
77 print('')
78 print( ('%-20s| %-16s| %s'):format('Model','CRC', 'CRC reverse','bigEnd', 'bigEnd','little','little'))
79 print( string.rep('-',60) )
80 local lists, err = core.reveng_models(width)
81 if lists == nil then return oops(err) end
83 for _,i in pairs(lists) do
84 if string.len(i) > 1 then
85 local a1 = core.reveng_runmodel(i, data, false, '0')
86 local a2 = core.reveng_runmodel(i, data, true, '0')
87 local a3 = core.reveng_runmodel(i, data, false, 'b')
88 local a4 = core.reveng_runmodel(i, data, false, 'B')
89 local a5 = core.reveng_runmodel(i, data, false, 'l')
90 local a6 = core.reveng_runmodel(i, data, false, 'L')
91 print( ('%-20s| %-16s| %-16s| %-16s| %-16s| %-16s| %-16s'):format(i, a1:upper(), a2:upper(),a3:upper(),a4:upper(),a5:upper(),a6:upper() ) )
92 end
93 end
94 end
96 main(args)