Giter Site home page Giter Site logo

crc.jl's Introduction

Build Status Coverage Status

CRC

This is a Julia module for calculating Cyclic Redundancy Checksums (CRCs).

  • All the algorithms in the RevEng Catalogue are supported.

  • New algorithms can be easily added.

  • Calculation can be direct or via cached tables.

  • Only arrays of bytes are accepted as data (it's certainly possible to handle arbitrary sized sequences; previous versions did this, but it complicated the code for little practical gain so I removed it - please contact me if you want me to add it back).

Although the performance of CRC.jl is good, even faster CRC-32 checksums are possible using the heavily optimized C implementation in zlib via the CRC32.jl package, or using hardware-accelerated CRC-32c checksums in the CRC32c standard library.

Examples

Calculate a CRC-32 Sum

julia> using CRC

julia> crc32 = crc(CRC_32)
(anonymous function)

julia> crc32("123456789")
0xcbf43926

The function crc() constructs a lookup table, which is cached in the returned function (here, crc32()). Re-using crc32() to calculate a series of CRCs is therefore more efficient than starting with crc() each time.

The returned function can also be called with a file handle, so calling open(crc32, file) will return the checksum of file.

Within Your Program

The same example as above, but inside your program, would look like this:

using CRC
...
crc32 = crc(CRC_32)  # create our own crc function, just once
...
function some_func(...)
    ...
    x = crc32(data)  # use the crc function created above, many times
    ...
end
...

Force Direct (Tableless) Calculation

julia> crc(CRC_32, tables=NoTables)("123456789")
0xcbf43926

Define an Algorithm

For example, CRC-7, catalogued as width=7 poly=0x09 init=0x00 refin=false refout=false xorout=0x00 check=0x75 name="CRC-7"

julia> myCRC7 = spec(7, 0x09, 0x00, false, false, 0x00, 0x75)
CRC.Spec{UInt8}(7, 0x09, 0x00, false, false, 0x00, 0x75)

julia> @assert crc(myCRC7)(CHECK) == myCRC7.check

Of course, this is already defined:

julia> CRC_7
CRC.Spec{UInt8}(7, 0x09, 0x00, false, false, 0x00, 0x75)

Installation

Julia can be downloaded here. Once Julia is working you can install this package using:

julia> Pkg.add("CRC")

Versions

  • 4.0.0 - 2020-11-27 Remove command line functionality.

  • 3.1.0 - 2020-11-07 Update ArgParse dependency and add Project.toml.

  • 3.0.0 - 2018-02-28 Update for Julia 1.0

  • 1.2.0 - 2016-09-28 Drop Julia 0.3 support and switch to Libz.

  • 1.1.0 - 2015-06-09 Small fixes for Julia 0.4, Travis + Coverage.

  • 1.0.0 - 2014-06-31 Changed handler method so that a String is converted to bytes (instead of being treated as a file path). This will break existing code that uses the current handler (sorry!), but I hope I don't have many users (particularly users that are calling that method)!

  • 0.2.0 - Initial release(s).

crc.jl's People

Contributors

andrewcooke avatar catawbasam avatar gunnarfarneback avatar keno avatar laborg avatar perrutquist avatar ranjanan avatar stevengj avatar tanmaykm avatar yuyichao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

crc.jl's Issues

Update availble for predefined CRCs from RevEng reference website

Hello!

TL;DR: I share an updated list (as code for copy/pasting) below, incase an update would be desirable.

Thanks for taking the time to implement CRC.jl - I recently discovered and found it very practical for some work I was doing with CAN-bus data. The protocol I was working with does not use one of the pre-defined CRCs in CRC.jl (v4.0.0) so I went looking at the referenced website, RevEng, to see if it was there.

It happens that it wasn't there, but whilst I was looking I wrote a bit of code which looks at the RevEng website for CRC definitions, and then writes a block of Julia code which could be updated in CRC.jl to support the most up to date list from the RevEng website.

In CRC.jl, I count ≈ 65 CRCs predefined. My code logged 112 CRCs from the RevEng website (accessed today) - I wondered that perhaps it was a while since the list was updated.

Please feel free to check it and if it looks ok, make use of it for a future version of CRC.jl if you'd like.


If the code which generated this list would be of any use to help keep this aspect of CRC.jl up to date, please let me know how best to share it (regrettably I'm quite new and I don't know my way around 'pull requests' yet).

I also wrote a few lines of code which autmatically generate the exported CRCs and the big dictionary of all of these, without having to write each line of code for each of the 65 (or 112) defined CRCs.
- It might help if there was interest to have CRC.jl automatically update by cross checking the RevEng website.
- That said, I don't know if there is a demand for a feature like this, and the automatic updates would only go for as long as the RevEng website remained online.
- Therefore I got this code to write its output to a file which could just be copied and pasted, because I thought this might be of more use and fitting with the design of CRC.jl as it is right now.
- Nevertheless if an auto-updating feature would be of any interest, I'd be happy to share this as well, just let me know how.


Finally, I noticed that the Dict which contains all of the different pre-defined CRCs is defined with the keyword const:

const ALL = Dict{Symbol,Spec}(:CRC_3_ROHC=>CRC_3_ROHC, # code continues on following lines

In the Julia documentation, I read:

"Note that "constant-ness" does not extend into mutable containers; only the association between a variable and its value is constant. If x is an array or dictionary (for example) you can still modify, add, or remove elements."

I don't expect it to be causing any problems the way it is defined, but I am curious if there is a reason why this is defined in this way (so I can learn if there are other reasons why this is handy in this situation). If you have a minute to help me understand better I'd be grateful!

Thanks for your time and have a nice day!

J


Updated list of CRCs from RevEng reference website.

CRC_3_GSM =                   spec(3, 0x03, 0x00, false, false, 0x07, 0x04)
CRC_3_ROHC =                  spec(3, 0x03, 0x07, true, true, 0x00, 0x06)
CRC_4_G_704 =                 spec(4, 0x03, 0x00, true, true, 0x00, 0x07)
CRC_4_INTERLAKEN =            spec(4, 0x03, 0x0f, false, false, 0x0f, 0x0b)
CRC_5_EPC_C1G2 =              spec(5, 0x09, 0x09, false, false, 0x00, 0x00)
CRC_5_G_704 =                 spec(5, 0x15, 0x00, true, true, 0x00, 0x07)
CRC_5_USB =                   spec(5, 0x05, 0x1f, true, true, 0x1f, 0x19)
CRC_6_CDMA2000_A =            spec(6, 0x27, 0x3f, false, false, 0x00, 0x0d)
CRC_6_CDMA2000_B =            spec(6, 0x07, 0x3f, false, false, 0x00, 0x3b)
CRC_6_DARC =                  spec(6, 0x19, 0x00, true, true, 0x00, 0x26)
CRC_6_G_704 =                 spec(6, 0x03, 0x00, true, true, 0x00, 0x06)
CRC_6_GSM =                   spec(6, 0x2f, 0x00, false, false, 0x3f, 0x13)
CRC_7_MMC =                   spec(7, 0x09, 0x00, false, false, 0x00, 0x75)
CRC_7_ROHC =                  spec(7, 0x4f, 0x7f, true, true, 0x00, 0x53)
CRC_7_UMTS =                  spec(7, 0x45, 0x00, false, false, 0x00, 0x61)
CRC_8_AUTOSAR =               spec(8, 0x2f, 0xff, false, false, 0xff, 0xdf)
CRC_8_BLUETOOTH =             spec(8, 0xa7, 0x00, true, true, 0x00, 0x26)
CRC_8_CDMA2000 =              spec(8, 0x9b, 0xff, false, false, 0x00, 0xda)
CRC_8_DARC =                  spec(8, 0x39, 0x00, true, true, 0x00, 0x15)
CRC_8_DVB_S2 =                spec(8, 0xd5, 0x00, false, false, 0x00, 0xbc)
CRC_8_GSM_A =                 spec(8, 0x1d, 0x00, false, false, 0x00, 0x37)
CRC_8_GSM_B =                 spec(8, 0x49, 0x00, false, false, 0xff, 0x94)
CRC_8_HITAG =                 spec(8, 0x1d, 0xff, false, false, 0x00, 0xb4)
CRC_8_I_432_1 =               spec(8, 0x07, 0x00, false, false, 0x55, 0xa1)
CRC_8_I_CODE =                spec(8, 0x1d, 0xfd, false, false, 0x00, 0x7e)
CRC_8_LTE =                   spec(8, 0x9b, 0x00, false, false, 0x00, 0xea)
CRC_8_MAXIM_DOW =             spec(8, 0x31, 0x00, true, true, 0x00, 0xa1)
CRC_8_MIFARE_MAD =            spec(8, 0x1d, 0xc7, false, false, 0x00, 0x99)
CRC_8_NRSC_5 =                spec(8, 0x31, 0xff, false, false, 0x00, 0xf7)
CRC_8_OPENSAFETY =            spec(8, 0x2f, 0x00, false, false, 0x00, 0x3e)
CRC_8_ROHC =                  spec(8, 0x07, 0xff, true, true, 0x00, 0xd0)
CRC_8_SAE_J1850 =             spec(8, 0x1d, 0xff, false, false, 0xff, 0x4b)
CRC_8_SMBUS =                 spec(8, 0x07, 0x00, false, false, 0x00, 0xf4)
CRC_8_TECH_3250 =             spec(8, 0x1d, 0xff, true, true, 0x00, 0x97)
CRC_8_WCDMA =                 spec(8, 0x9b, 0x00, true, true, 0x00, 0x25)
CRC_10_ATM =                  spec(10, 0x0233, 0x00, false, false, 0x00, 0x0199)
CRC_10_CDMA2000 =             spec(10, 0x03d9, 0x03ff, false, false, 0x00, 0x0233)
CRC_10_GSM =                  spec(10, 0x0175, 0x00, false, false, 0x03ff, 0x012a)
CRC_11_FLEXRAY =              spec(11, 0x0385, 0x1a, false, false, 0x00, 0x05a3)
CRC_11_UMTS =                 spec(11, 0x0307, 0x00, false, false, 0x00, 0x61)
CRC_12_CDMA2000 =             spec(12, 0x0f13, 0x0fff, false, false, 0x00, 0x0d4d)
CRC_12_DECT =                 spec(12, 0x080f, 0x00, false, false, 0x00, 0x0f5b)
CRC_12_GSM =                  spec(12, 0x0d31, 0x00, false, false, 0x0fff, 0x0b34)
CRC_12_UMTS =                 spec(12, 0x080f, 0x00, false, true, 0x00, 0x0daf)
CRC_13_BBC =                  spec(13, 0x1cf5, 0x00, false, false, 0x00, 0x04fa)
CRC_14_DARC =                 spec(14, 0x0805, 0x00, true, true, 0x00, 0x082d)
CRC_14_GSM =                  spec(14, 0x202d, 0x00, false, false, 0x3fff, 0x30ae)
CRC_15_CAN =                  spec(15, 0x4599, 0x00, false, false, 0x00, 0x059e)
CRC_15_MPT1327 =              spec(15, 0x6815, 0x00, false, false, 0x01, 0x2566)
CRC_16_ARC =                  spec(16, 0x8005, 0x00, true, true, 0x00, 0xbb3d)
CRC_16_CDMA2000 =             spec(16, 0xc867, 0xffff, false, false, 0x00, 0x4c06)
CRC_16_CMS =                  spec(16, 0x8005, 0xffff, false, false, 0x00, 0xaee7)
CRC_16_DDS_110 =              spec(16, 0x8005, 0x800d, false, false, 0x00, 0x9ecf)
CRC_16_DECT_R =               spec(16, 0x0589, 0x00, false, false, 0x01, 0x7e)
CRC_16_DECT_X =               spec(16, 0x0589, 0x00, false, false, 0x00, 0x7f)
CRC_16_DNP =                  spec(16, 0x3d65, 0x00, true, true, 0xffff, 0xea82)
CRC_16_EN_13757 =             spec(16, 0x3d65, 0x00, false, false, 0xffff, 0xc2b7)
CRC_16_GENIBUS =              spec(16, 0x1021, 0xffff, false, false, 0xffff, 0xd64e)
CRC_16_GSM =                  spec(16, 0x1021, 0x00, false, false, 0xffff, 0xce3c)
CRC_16_IBM_3740 =             spec(16, 0x1021, 0xffff, false, false, 0x00, 0x29b1)
CRC_16_IBM_SDLC =             spec(16, 0x1021, 0xffff, true, true, 0xffff, 0x906e)
CRC_16_ISO_IEC_14443_3_A =    spec(16, 0x1021, 0xc6c6, true, true, 0x00, 0xbf05)
CRC_16_KERMIT =               spec(16, 0x1021, 0x00, true, true, 0x00, 0x2189)
CRC_16_LJ1200 =               spec(16, 0x6f63, 0x00, false, false, 0x00, 0xbdf4)
CRC_16_M17 =                  spec(16, 0x5935, 0xffff, false, false, 0x00, 0x772b)
CRC_16_MAXIM_DOW =            spec(16, 0x8005, 0x00, true, true, 0xffff, 0x44c2)
CRC_16_MCRF4XX =              spec(16, 0x1021, 0xffff, true, true, 0x00, 0x6f91)
CRC_16_MODBUS =               spec(16, 0x8005, 0xffff, true, true, 0x00, 0x4b37)
CRC_16_NRSC_5 =               spec(16, 0x080b, 0xffff, true, true, 0x00, 0xa066)
CRC_16_OPENSAFETY_A =         spec(16, 0x5935, 0x00, false, false, 0x00, 0x5d38)
CRC_16_OPENSAFETY_B =         spec(16, 0x755b, 0x00, false, false, 0x00, 0x20fe)
CRC_16_PROFIBUS =             spec(16, 0x1dcf, 0xffff, false, false, 0xffff, 0xa819)
CRC_16_RIELLO =               spec(16, 0x1021, 0xb2aa, true, true, 0x00, 0x63d0)
CRC_16_SPI_FUJITSU =          spec(16, 0x1021, 0x1d0f, false, false, 0x00, 0xe5cc)
CRC_16_T10_DIF =              spec(16, 0x8bb7, 0x00, false, false, 0x00, 0xd0db)
CRC_16_TELEDISK =             spec(16, 0xa097, 0x00, false, false, 0x00, 0x0fb3)
CRC_16_TMS37157 =             spec(16, 0x1021, 0x89ec, true, true, 0x00, 0x26b1)
CRC_16_UMTS =                 spec(16, 0x8005, 0x00, false, false, 0x00, 0xfee8)
CRC_16_USB =                  spec(16, 0x8005, 0xffff, true, true, 0xffff, 0xb4c8)
CRC_16_XMODEM =               spec(16, 0x1021, 0x00, false, false, 0x00, 0x31c3)
CRC_17_CAN_FD =               spec(17, 0x0001685b, 0x00, false, false, 0x00, 0x4f03)
CRC_21_CAN_FD =               spec(21, 0x00102899, 0x00, false, false, 0x00, 0x000ed841)
CRC_24_BLE =                  spec(24, 0x065b, 0x00555555, true, true, 0x00, 0x00c25a56)
CRC_24_FLEXRAY_A =            spec(24, 0x005d6dcb, 0x00fedcba, false, false, 0x00, 0x007979bd)
CRC_24_FLEXRAY_B =            spec(24, 0x005d6dcb, 0x00abcdef, false, false, 0x00, 0x001f23b8)
CRC_24_INTERLAKEN =           spec(24, 0x00328b63, 0x00ffffff, false, false, 0x00ffffff, 0x00b4f3e6)
CRC_24_LTE_A =                spec(24, 0x00864cfb, 0x00, false, false, 0x00, 0x00cde703)
CRC_24_LTE_B =                spec(24, 0x00800063, 0x00, false, false, 0x00, 0x0023ef52)
CRC_24_OPENPGP =              spec(24, 0x00864cfb, 0x00b704ce, false, false, 0x00, 0x0021cf02)
CRC_24_OS_9 =                 spec(24, 0x00800063, 0x00ffffff, false, false, 0x00ffffff, 0x00200fa5)
CRC_30_CDMA =                 spec(30, 0x2030b9c7, 0x3fffffff, false, false, 0x3fffffff, 0x04c34abf)
CRC_31_PHILIPS =              spec(31, 0x04c11db7, 0x7fffffff, false, false, 0x7fffffff, 0x0ce9e46c)
CRC_32_AIXM =                 spec(32, 0x814141ab, 0x00, false, false, 0x00, 0x3010bf7f)
CRC_32_AUTOSAR =              spec(32, 0xf4acfb13, 0xffffffff, true, true, 0xffffffff, 0x1697d06a)
CRC_32_BASE91_D =             spec(32, 0xa833982b, 0xffffffff, true, true, 0xffffffff, 0x87315576)
CRC_32_BZIP2 =                spec(32, 0x04c11db7, 0xffffffff, false, false, 0xffffffff, 0xfc891918)
CRC_32_CD_ROM_EDC =           spec(32, 0x8001801b, 0x00, true, true, 0x00, 0x6ec2edc4)
CRC_32_CKSUM =                spec(32, 0x04c11db7, 0x00, false, false, 0xffffffff, 0x765e7680)
CRC_32_ISCSI =                spec(32, 0x1edc6f41, 0xffffffff, true, true, 0xffffffff, 0xe3069283)
CRC_32_ISO_HDLC =             spec(32, 0x04c11db7, 0xffffffff, true, true, 0xffffffff, 0xcbf43926)
CRC_32_JAMCRC =               spec(32, 0x04c11db7, 0xffffffff, true, true, 0x00, 0x340bc6d9)
CRC_32_MEF =                  spec(32, 0x741b8cd7, 0xffffffff, true, true, 0x00, 0xd2c22f51)
CRC_32_MPEG_2 =               spec(32, 0x04c11db7, 0xffffffff, false, false, 0x00, 0x0376e6e7)
CRC_32_XFER =                 spec(32, 0xaf, 0x00, false, false, 0x00, 0xbd0be338)
CRC_40_GSM =                  spec(40, 0x04820009, 0x00, false, false, 0x000000ffffffffff, 0x000000d4164fc646)
CRC_64_ECMA_182 =             spec(64, 0x42f0e1eba9ea3693, 0x00, false, false, 0x00, 0x6c40df5f0b497347)
CRC_64_GO_ISO =               spec(64, 0x1b, 0xffffffffffffffff, true, true, 0xffffffffffffffff, 0xb90956c775a41001)
CRC_64_MS =                   spec(64, 0x259c84cba6426349, 0xffffffffffffffff, true, true, 0x00, 0x75d4b74f024eceea)
CRC_64_REDIS =                spec(64, 0xad93d23594c935a9, 0x00, true, true, 0x00, 0xe9c6d914c4b8d9ca)
CRC_64_WE =                   spec(64, 0x42f0e1eba9ea3693, 0xffffffffffffffff, false, false, 0xffffffffffffffff, 0x62ec59e3f1a4f00a)
CRC_64_XZ =                   spec(64, 0x42f0e1eba9ea3693, 0xffffffffffffffff, true, true, 0xffffffffffffffff, 0x995dc9bbdf1939fa)
CRC_82_DARC =                 spec(82, 0x000000000000308c0111011401440411, 0x00, true, true, 0x00, 0x0000000000009ea83f625023801fd612)

const ALL = Dict{Symbol,Spec}(
    :CRC_3_GSM => CRC_3_GSM, 
    :CRC_3_ROHC => CRC_3_ROHC, 
    :CRC_4_G_704 => CRC_4_G_704, 
    :CRC_4_INTERLAKEN => CRC_4_INTERLAKEN, 
    :CRC_5_EPC_C1G2 => CRC_5_EPC_C1G2, 
    :CRC_5_G_704 => CRC_5_G_704, 
    :CRC_5_USB => CRC_5_USB, 
    :CRC_6_CDMA2000_A => CRC_6_CDMA2000_A, 
    :CRC_6_CDMA2000_B => CRC_6_CDMA2000_B, 
    :CRC_6_DARC => CRC_6_DARC, 
    :CRC_6_G_704 => CRC_6_G_704, 
    :CRC_6_GSM => CRC_6_GSM, 
    :CRC_7_MMC => CRC_7_MMC, 
    :CRC_7_ROHC => CRC_7_ROHC, 
    :CRC_7_UMTS => CRC_7_UMTS, 
    :CRC_8_AUTOSAR => CRC_8_AUTOSAR, 
    :CRC_8_BLUETOOTH => CRC_8_BLUETOOTH, 
    :CRC_8_CDMA2000 => CRC_8_CDMA2000, 
    :CRC_8_DARC => CRC_8_DARC, 
    :CRC_8_DVB_S2 => CRC_8_DVB_S2, 
    :CRC_8_GSM_A => CRC_8_GSM_A, 
    :CRC_8_GSM_B => CRC_8_GSM_B, 
    :CRC_8_HITAG => CRC_8_HITAG, 
    :CRC_8_I_432_1 => CRC_8_I_432_1, 
    :CRC_8_I_CODE => CRC_8_I_CODE, 
    :CRC_8_LTE => CRC_8_LTE, 
    :CRC_8_MAXIM_DOW => CRC_8_MAXIM_DOW, 
    :CRC_8_MIFARE_MAD => CRC_8_MIFARE_MAD, 
    :CRC_8_NRSC_5 => CRC_8_NRSC_5, 
    :CRC_8_OPENSAFETY => CRC_8_OPENSAFETY, 
    :CRC_8_ROHC => CRC_8_ROHC, 
    :CRC_8_SAE_J1850 => CRC_8_SAE_J1850, 
    :CRC_8_SMBUS => CRC_8_SMBUS, 
    :CRC_8_TECH_3250 => CRC_8_TECH_3250, 
    :CRC_8_WCDMA => CRC_8_WCDMA, 
    :CRC_10_ATM => CRC_10_ATM, 
    :CRC_10_CDMA2000 => CRC_10_CDMA2000, 
    :CRC_10_GSM => CRC_10_GSM, 
    :CRC_11_FLEXRAY => CRC_11_FLEXRAY, 
    :CRC_11_UMTS => CRC_11_UMTS, 
    :CRC_12_CDMA2000 => CRC_12_CDMA2000, 
    :CRC_12_DECT => CRC_12_DECT, 
    :CRC_12_GSM => CRC_12_GSM, 
    :CRC_12_UMTS => CRC_12_UMTS, 
    :CRC_13_BBC => CRC_13_BBC, 
    :CRC_14_DARC => CRC_14_DARC, 
    :CRC_14_GSM => CRC_14_GSM, 
    :CRC_15_CAN => CRC_15_CAN, 
    :CRC_15_MPT1327 => CRC_15_MPT1327, 
    :CRC_16_ARC => CRC_16_ARC, 
    :CRC_16_CDMA2000 => CRC_16_CDMA2000, 
    :CRC_16_CMS => CRC_16_CMS, 
    :CRC_16_DDS_110 => CRC_16_DDS_110, 
    :CRC_16_DECT_R => CRC_16_DECT_R, 
    :CRC_16_DECT_X => CRC_16_DECT_X, 
    :CRC_16_DNP => CRC_16_DNP, 
    :CRC_16_EN_13757 => CRC_16_EN_13757, 
    :CRC_16_GENIBUS => CRC_16_GENIBUS, 
    :CRC_16_GSM => CRC_16_GSM, 
    :CRC_16_IBM_3740 => CRC_16_IBM_3740, 
    :CRC_16_IBM_SDLC => CRC_16_IBM_SDLC, 
    :CRC_16_ISO_IEC_14443_3_A => CRC_16_ISO_IEC_14443_3_A, 
    :CRC_16_KERMIT => CRC_16_KERMIT, 
    :CRC_16_LJ1200 => CRC_16_LJ1200, 
    :CRC_16_M17 => CRC_16_M17, 
    :CRC_16_MAXIM_DOW => CRC_16_MAXIM_DOW, 
    :CRC_16_MCRF4XX => CRC_16_MCRF4XX, 
    :CRC_16_MODBUS => CRC_16_MODBUS, 
    :CRC_16_NRSC_5 => CRC_16_NRSC_5, 
    :CRC_16_OPENSAFETY_A => CRC_16_OPENSAFETY_A, 
    :CRC_16_OPENSAFETY_B => CRC_16_OPENSAFETY_B, 
    :CRC_16_PROFIBUS => CRC_16_PROFIBUS, 
    :CRC_16_RIELLO => CRC_16_RIELLO, 
    :CRC_16_SPI_FUJITSU => CRC_16_SPI_FUJITSU, 
    :CRC_16_T10_DIF => CRC_16_T10_DIF, 
    :CRC_16_TELEDISK => CRC_16_TELEDISK, 
    :CRC_16_TMS37157 => CRC_16_TMS37157, 
    :CRC_16_UMTS => CRC_16_UMTS, 
    :CRC_16_USB => CRC_16_USB, 
    :CRC_16_XMODEM => CRC_16_XMODEM, 
    :CRC_17_CAN_FD => CRC_17_CAN_FD, 
    :CRC_21_CAN_FD => CRC_21_CAN_FD, 
    :CRC_24_BLE => CRC_24_BLE, 
    :CRC_24_FLEXRAY_A => CRC_24_FLEXRAY_A, 
    :CRC_24_FLEXRAY_B => CRC_24_FLEXRAY_B, 
    :CRC_24_INTERLAKEN => CRC_24_INTERLAKEN, 
    :CRC_24_LTE_A => CRC_24_LTE_A, 
    :CRC_24_LTE_B => CRC_24_LTE_B, 
    :CRC_24_OPENPGP => CRC_24_OPENPGP, 
    :CRC_24_OS_9 => CRC_24_OS_9, 
    :CRC_30_CDMA => CRC_30_CDMA, 
    :CRC_31_PHILIPS => CRC_31_PHILIPS, 
    :CRC_32_AIXM => CRC_32_AIXM, 
    :CRC_32_AUTOSAR => CRC_32_AUTOSAR, 
    :CRC_32_BASE91_D => CRC_32_BASE91_D, 
    :CRC_32_BZIP2 => CRC_32_BZIP2, 
    :CRC_32_CD_ROM_EDC => CRC_32_CD_ROM_EDC, 
    :CRC_32_CKSUM => CRC_32_CKSUM, 
    :CRC_32_ISCSI => CRC_32_ISCSI, 
    :CRC_32_ISO_HDLC => CRC_32_ISO_HDLC, 
    :CRC_32_JAMCRC => CRC_32_JAMCRC, 
    :CRC_32_MEF => CRC_32_MEF, 
    :CRC_32_MPEG_2 => CRC_32_MPEG_2, 
    :CRC_32_XFER => CRC_32_XFER, 
    :CRC_40_GSM => CRC_40_GSM, 
    :CRC_64_ECMA_182 => CRC_64_ECMA_182, 
    :CRC_64_GO_ISO => CRC_64_GO_ISO, 
    :CRC_64_MS => CRC_64_MS, 
    :CRC_64_REDIS => CRC_64_REDIS, 
    :CRC_64_WE => CRC_64_WE, 
    :CRC_64_XZ => CRC_64_XZ, 
    :CRC_82_DARC => CRC_82_DARC, 
)

Written using:

(@v1.10) pkg> st CRC
Status `~/.julia/environments/v1.10/Project.toml`
  [44b605c4] CRC v4.0.0
julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (x86_64-apple-darwin22.4.0)
  CPU: 4 × Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, broadwell)
  Threads: 1 on 4 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 

Support BitArray input

Awesome package!

A feature request to support BitArray inputs, or inputs that are not an even multiple of bytes. This is common i e.g. wireless applications.

I would happily give it a go myself, but not sure if I have the competence (after briefly browsing the code). I hope to give it Another try whenever I find the time.

crc32 convenience function?

The page for https://github.com/fhs/CRC32.jl declares it deprecated and suggests CRC.jl.

However, CRC32.jl had a simpler interface:
crc = crc32("hello")

In my code I have:
crc32(string) = crc(CRC_32)(convert(Vector{Uint8}, string))
I use this to do:
@assert r.headers["x-amz-crc32"] == string(crc32(r.data))

My guess is that this is a common use-case for a CRC library. I would rather not have to paste in my crc32() just after using CRC every time I use it.
So, I would like to request addition of a convenience function crc32(s::String).

I'm happy to fork and send a pull request it you like.

[PackageEvaluator.jl] Your package CRC may have a testing issue.

This issue is being filed by a script, but if you reply, I will see it.

PackageEvaluator.jl is a script that runs nightly. It attempts to load all Julia packages and run their test (if available) on both the stable version of Julia (0.2) and the nightly build of the unstable version (0.3).

The results of this script are used to generate a package listing enhanced with testing results.

The status of this package, CRC, on...

  • Julia 0.2 is 'Package was untestable.' PackageEvaluator.jl
  • Julia 0.3 is 'Tests fail, but package loads.' PackageEvaluator.jl

'No tests, but package loads.' can be due to their being no tests (you should write some if you can!) but can also be due to PackageEvaluator not being able to find your tests. Consider adding a test/runtests.jl file.

'Package doesn't load.' is the worst-case scenario. Sometimes this arises because your package doesn't have BinDeps support, or needs something that can't be installed with BinDeps. If this is the case for your package, please file an issue and an exception can be made so your package will not be tested.

This automatically filed issue is a one-off message. Starting soon, issues will only be filed when the testing status of your package changes in a negative direction (gets worse). If you'd like to opt-out of these status-change messages, reply to this message.

failure on Julia v0.5

I encountered this error (UndefVarError: A not defined) in my use of the package. The same error also shows up while running the tests.

julia> versioninfo()
Julia Version 0.5.0-dev+4553
Commit f4cb80b* (2016-06-06 02:05 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, haswell)

julia> using CRC

julia> Pkg.test("CRC")
INFO: Computing test dependencies for CRC...
INFO: No packages to install, update or remove
INFO: Testing CRC
Error During Test
  Test threw an exception of type UndefVarError
  Expression: crc32("abcxyz") == 0xacc462e9
  UndefVarError: A not defined
   in (::CRC.##handler#4#8{CRC.Spec{UInt32},DataType,CRC.Backwards{UInt64}})(::Bool, ::Function, ::Array{UInt8,1}) at /home/tan/.julia/v0.5/CRC/src/CRC.jl:372
   in (::CRC.#kw##handler#7)(::Array{Any,1}, ::CRC.#handler#7, ::Array{UInt8,1}) at ./null:0
   in (::CRC.##handler#6#10)(::Bool, ::Function, ::String) at /home/tan/.julia/v0.5/CRC/src/CRC.jl:384
   in (::CRC.#handler#7)(::String) at /home/tan/.julia/v0.5/CRC/src/CRC.jl:384
   in test_string() at /home/tan/.julia/v0.5/CRC/test/runtests.jl:52
   in tests() at /home/tan/.julia/v0.5/CRC/test/runtests.jl:56
   in include_from_node1(::String) at ./loading.jl:426
   in process_options(::Base.JLOptions) at ./client.jl:266
   in _start() at ./client.jl:322
ERROR: LoadError: There was an error during testing
 in record(::Base.Test.FallbackTestSet, ::Base.Test.Error) at ./test.jl:321
 in do_test(::Base.Test.Threw, ::Expr) at ./test.jl:219
 in test_string() at /home/tan/.julia/v0.5/CRC/test/runtests.jl:52
 in tests() at /home/tan/.julia/v0.5/CRC/test/runtests.jl:56
 in include_from_node1(::String) at ./loading.jl:426
 in process_options(::Base.JLOptions) at ./client.jl:266
 in _start() at ./client.jl:322
while loading /home/tan/.julia/v0.5/CRC/test/runtests.jl, in expression starting on line 67

resize! fails after using crc

julia> using CRC

julia> crc32c = crc(CRC_32_C)
handler (generic function with 3 methods)

julia> a = b"hello world";

julia> crc32c(a)
0xc99465aa

julia> resize!(a, 5)
ERROR: cannot resize array with shared data
 in resize! at ./array.jl:545

In my code I reuse a buffer to repeatedly receive bytes. Buffer is occasionally re-sized when the packet size changes. I am on:

julia> versioninfo()
Julia Version 0.4.0-dev+3373
Commit 491c9b6* (2015-02-16 04:39 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

Document mapping between bits and UInt8 array

Hi, thanks for the library. I have a few questions I couldn't answer from reading the code, though.

How does one need to map a Vector{Bool} to a Vector{UInt8}? Where is the LSB/MSB? Is it big or little endian? How is this affected by the RefIn/RefOut parameters?

In particular, how are Vector{Bool}s with a length that is not a multiple of 8 mapped? Should the first element or the last element of the Vector{UInt8} be padded? And should it be padded from its MSB or from its LSB?

I believe, the mapping should be chosen in a way, so that crcgen(bit2crc([u; crc2bit(crcgen(bit2crc(u)))])) == 0 for any crcgen = crc(spec) and any u, if I'm not mistaken.

upgrade to Julia 0.6

Hi, great package.
Are there any plans to fix the deprecation warnings for Julia 0.6 ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.