Giter VIP home page Giter VIP logo

digest-crc's Introduction

Digest CRC

Description

Adds support for calculating Cyclic Redundancy Check (CRC) to the Digest module.

Features

  • Provides support for the following CRC algorithms:
    • {Digest::CRC1 CRC1}
    • {Digest::CRC5 CRC5}
    • {Digest::CRC8 CRC8}
    • {Digest::CRC81Wire CRC8 1-Wire}
    • {Digest::CRC16 CRC16}
    • {Digest::CRC16CCITT CRC16 CCITT}
    • {Digest::CRC16DNP CRC16 DNP}
    • {Digest::CRC16Modbus CRC16 Modbus}
    • {Digest::CRC16USB CRC16 USB}
    • {Digest::CRC16XModem CRC16 XModem}
    • {Digest::CRC16ZModem CRC16 ZModem}
    • {Digest::CRC16QT CRC16 QT}
    • {Digest::CRC24 CRC24}
    • {Digest::CRC32 CRC32}
    • {Digest::CRC32c CRC32c}
    • {Digest::CRC32Mpeg CRC32 Mpeg}
    • {Digest::CRC64 CRC64}
  • Pure Ruby implementation.
  • Provides CRC Tables for optimized calculations.

Install

gem install digest-crc

Examples

Calculate a CRC32:

require 'digest/crc32'

Digest::CRC32.hexdigest('hello')
# => "3610a686"

Calculate a CRC32 of a file:

Digest::CRC32.file('README.md')
# => #<Digest::CRC32: 127ad531>

Incrementally calculate a CRC32:

crc = Digest::CRC32.new
crc << 'one'
crc << 'two'
crc << 'three'
crc.hexdigest
# => "09e1c092"

Directly access the checksum:

crc.checksum
# => 165789842

Defining your own CRC class:

require 'digest/crc32'

module Digest
  class CRC3000 < CRC32

    WIDTH = 4

    INIT_CRC = 0xffffffff

    XOR_MASK = 0xffffffff

    TABLE = [
      # ....
    ].freeze

    def update(data)
      data.each_byte do |b|
        @crc = (((@crc >> 8) & 0x00ffffff) ^ @table[(@crc ^ b) & 0xff])
      end

      return self
    end
  end
end

Thanks

Special thanks go out to the pycrc library which is able to generate C source-code for all of the CRC algorithms, including their CRC Tables.

License

Copyright (c) 2010-2014 Hal Brodigan

See {file:LICENSE.txt} for license information.

digest-crc's People

Contributors

postmodern avatar korun avatar nofxx avatar joelhelbling avatar

Stargazers

Yongbo avatar

Watchers

James Cloos avatar

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.