1 local getopt
= require('getopt')
2 local utils
= require('utils')
3 local ansicolors
= require('ansicolors')
9 This script calculates many checksums (CRC) over the provided hex input.
12 script run data_hex_crc -b 010203040506070809
13 script run data_hex_crc -b 010203040506070809 -w 16
16 script run data_hex_crc [-b <hex bytes] [-w <width>]
20 -w bitwidth of the CRC family of algorithm. <optional> defaults to all known CRC presets.
23 -- A debug printout-function
24 local function dbg(args
)
25 if not DEBUG
then return end
26 if type(args
) == 'table' then
37 -- This is only meant to be used when errors occur
38 local function oops(err
)
40 core
.clearCommandBuffer()
50 print(ansicolors
.cyan
..'Usage'..ansicolors
.reset
)
52 print(ansicolors
.cyan
..'Arguments'..ansicolors
.reset
)
54 print(ansicolors
.cyan
..'Example usage'..ansicolors
.reset
)
58 -- The main entry point
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
71 data
= data
or '01020304'
74 print( string.rep('-',60) )
75 print('Bit width of CRC | '..width
)
76 print('Bytes | '..data
)
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() ) )