🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

github.com/yousifnimah/golang-crc

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/yousifnimah/golang-crc

v1.0.0
Source
Go
Version published
Created
Source

Golang CRC (Cyclic Redundancy Check)

Comprehensive Go Language (Golang) CRC Library, Supporting CRC8, CRC16, CRC32 and CRC64.

CRC (Cyclic Redundancy Check) is an error detection algorithm that generates a checksum based on the data being transmitted. In Go (Golang), you can implement CRC using various algorithms, such as CRC-8, CRC-16, CRC-32 or CRC-64.

Table of Contents

  • Installation
  • Get started

Installation

go get github.com/yousifnimah/Cryptx

Get Started

  • CRC-8 Usage

    1 - Importing package into main package

    import ("github.com/yousifnimah/Cryptx/CRC8")
    

    2 - Use algorithm name from the table below:

    AlgorithmPolynomialInitial ValueXOROUT
    CRC-80x070x000x00
    ITU0x070x000x55
    ROHC0x070xFF0x00
    SAE-J18500x1D0xFF0xFF
    SAE-J1850_ZERO0x1D0x000x00
    8H2F0x2F0xFF0xFF
    CDMA20000x9B0xFF0x00
    DARC0x390x000x00
    DVB_S20xD50x000x00
    EBU0x1D0xFF0x00
    ICODE0x1D0xFD0x00
    MAXIM0x310x000x00
    WCDMA0x9B0x000x00

    In main.go:

    package main
    
    import (
    "fmt"
    "github.com/yousifnimah/Cryptx/CRC8"
    )
    
    func main() {
      Input := []byte("12345") //string to slice of bytes
      AlgorithmName := "ITU"   //CRC-8 algorithm name from supported table
      checksumHex := CRC8.ResultHex(Input, AlgorithmName)
      fmt.Println("Output:", checksumHex)
    }
    

    Result:

    Output: 0x9E
    

    You can get output in byte:

    Input := []byte("12345")
    checksumByte := CRC8.Result(Input, "ITU")
    fmt.Println("Output:", checksumByte)
    

  • CRC-16 Usage

    1 - Importing package

    import ("github.com/yousifnimah/Cryptx/CRC16")
    

    2 - Use algorithm name from the table below:

    AlgorithmPolynomialInitialValueXOROUT
    CCIT_ZERO0x10210x00000x0000
    ARC0x80050x00000x0000
    AUG_CCITT0x10210x1D0F0x0000
    BUYPASS0x80050x00000x0000
    CCITT_FALSE0x10210xFFFF0x0000
    CDMA20000xC8670xFFFF0xFFFF
    DDS_1100x80050x800D0x0000
    DECT_R0x5890x00000x0001
    DECT_X0x5890x00000x0000
    DNP0x3D650x00000xFFFF
    EN_137570x3D650x00000xFFFF
    GENIBUS0x10210xFFFF0xFFFF
    MAXIM0x80050x00000xFFFF
    MCRF4XX0x10210xFFFF0x0000
    RIELLO0x10210xB2AA0x0000
    T10_DIF0x8BB70x00000x0000
    TELEDISK0xA0970x00000x0000
    TMS371570x10210x89EC0x0000
    USB0x80050xFFFF0xFFFF
    A0x10210xC6C60x0000
    KERMIT0x10210x00000x0000
    MODBUS0x80050xFFFF0x0000
    X_250x10210xFFFF0xFFFF
    XMODEM0x10210x00000x0000
    IBM0x80050x00000x0000

    In main.go:

    package main
      
    import (
      "fmt"
      "github.com/yousifnimah/Cryptx/CRC16"
    )
    
    func main() { 
         Input := []byte("12345")     //string to slice of bytes 
         AlgorithmName := "CCIT_ZERO" //Algorithm name from supported table checksumHex := CRC16.ResultHex(Input, AlgorithmName)
         fmt.Println("Output:", checksumHex)
    }
    

    Result:

    Output: 0x546C
    
  • CRC-32 Usage

    1 - Importing package

    import ("Cryptx/CRC32")
    

    2 - Use algorithm name from the table below:

    AlgorithmPolynomialInitialValueXOROUT
    CRC-320x4C11DB70xFFFFFFFF0xFFFFFFFF
    BZIP20x4C11DB70xFFFFFFFF0xFFFFFFFF
    C0x1EDC6F410xFFFFFFFF0xFFFFFFFF
    D0xA833982B0xFFFFFFFF0xFFFFFFFF
    MPEG20x4C11DB70xFFFFFFFF0x0
    POSIX0x4C11DB70x00xFFFFFFFF
    Q0x814141AB0x00x0
    JAMCRC0x4C11DB70xFFFFFFFF0x0
    XFER0xAF0x00x0
    KOOPM0x741B8CD70xFFFFFFFF0xFFFFFFFF

    In main.go:

    package main
    
    import (
       "fmt"
       "github.com/yousifnimah/Cryptx/CRC32"
    )
    
    func main() {
          Input := []byte("12345") //string to slice of bytes
          AlgorithmName := "BZIP2" //Algorithm name from supported table
          checksumHex := CRC32.ResultHex(Input, AlgorithmName)
          fmt.Println("Output:", checksumHex)
    }
    

    Result:

    Output: 0x426548B8
    
  • CRC-64 Usage

    1 - Importing package

    import ("github.com/yousifnimah/Cryptx/CRC64")
    

    2 - Use algorithm name from the table below:

    AlgorithmPolynomialInitialValueXOROUT
    ECMA0x42F0E1EBA9EA36930xFFFFFFFFFFFFFFFF0xFFFFFFFFFFFFFFFF
    WE0x42F0E1EBA9EA36930xFFFFFFFFFFFFFFFF0xFFFFFFFFFFFFFFFF

    In main.go:

    package main
    
    import (
       "fmt"
       "github.com/yousifnimah/Cryptx/CRC64"
    )
    
    func main() {
       Input := []byte("12345") //string to slice of bytes
       AlgorithmName := "ECMA" //Algorithm name from supported table
       checksumHex := CRC64.ResultHex(Input, AlgorithmName)
       fmt.Println("Output:", checksumHex)
    }
    

    Result:

    Output: 0xDDEDF5CB80FA64E9
    

FAQs

Package last updated on 20 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts