1 local getopt = require('getopt')
2 local utils = require('utils')
4 example = "script calculates many different checksums (CRC) over the provided hex input"
8 This script calculates many checksums (CRC) over the provided hex input.
12 -w bitwidth of the CRC family of algorithm. <optional> defaults to all known CRC presets.
14 script run e -b 010203040506070809
15 script run e -b 010203040506070809 -w 16
19 -- A debug printout-function
26 -- This is only meant to be used when errors occur
35 print("Example usage")
39 -- The main entry point
45 -- Read the parameters
46 for o, a in getopt.getopt(args, 'hb:w:') do
47 if o == "h" then return help() end
48 if o == "b" then data = a end
49 if o == "w" then width = a end
52 data = data or '01020304'
54 print( string.rep('-',60) )
55 print('Bit width of CRC | '..width)
56 print('Bytes | '..data)
58 print( ('%-20s| %-16s| %s'):format('Model','CRC', 'CRC reverse'))
59 print( string.rep('-',60) )
60 local lists = core.reveng_models(width)
61 for _,i in pairs(lists) do
62 local a1 = core.reveng_runmodel(i, data, false, '0')
63 local a2 = core.reveng_runmodel(i, data, true, '0')
64 local a3 = core.reveng_runmodel(i, data, false, 'b')
65 local a4 = core.reveng_runmodel(i, data, false, 'B')
66 local a5 = core.reveng_runmodel(i, data, false, 'l')
67 local a6 = core.reveng_runmodel(i, data, false, 'L')
68 print( ('%-20s| %-16s| %-16s| %-16s| %-16s| %-16s| %-16s'):format(i, a1:upper(), a2:upper(),a3:upper(),a4:upper(),a5:upper(),a6:upper() ) )