Sha256: cbbbcf7fcb2478aeb9dac4f7a76f7f172393e5794bdc1a697ffd837360e6473a

Contents?: true

Size: 1.24 KB

Versions: 49

Compression:

Stored size: 1.24 KB

Contents

# -*- coding: binary -*-
module Rex
  module Text
    # We are re-opening the module to add these module methods.
    # Breaking them up this way allows us to maintain a little higher
    # degree of organisation and make it easier to find what you're looking for
    # without hanging the underlying calls that we historically rely upon.

    # @param str [String] Data to checksum
    # @return [Integer] 8-bit checksum
    def self.checksum8(str)
      (str.unpack("C*").inject(:+) || 0) % 0x100
    end

    # @param str [String] Little-endian data to checksum
    # @return [Integer] 16-bit checksum
    def self.checksum16_le(str)
      (str.unpack("v*").inject(:+) || 0) % 0x10000
    end

    # @param str [String] Big-endian data to checksum
    # @return [Integer] 16-bit checksum
    def self.checksum16_be(str)
      (str.unpack("n*").inject(:+) || 0) % 0x10000
    end

    # @param str [String] Little-endian data to checksum
    # @return [Integer] 32-bit checksum
    def self.checksum32_le(str)
      (str.unpack("V*").inject(:+) || 0) % 0x100000000
    end

    # @param str [String] Big-endian data to checksum
    # @return [Integer] 32-bit checksum
    def self.checksum32_be(str)
      (str.unpack("N*").inject(:+) || 0) % 0x100000000
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
rex-text-0.2.60 lib/rex/text/checksum.rb
rex-text-0.2.59 lib/rex/text/checksum.rb
rex-text-0.2.57 lib/rex/text/checksum.rb
rex-text-0.2.56 lib/rex/text/checksum.rb
rex-text-0.2.55 lib/rex/text/checksum.rb
rex-text-0.2.54 lib/rex/text/checksum.rb
rex-text-0.2.53 lib/rex/text/checksum.rb
rex-text-0.2.52 lib/rex/text/checksum.rb
rex-text-0.2.51 lib/rex/text/checksum.rb
rex-text-0.2.50 lib/rex/text/checksum.rb
rex-text-0.2.49 lib/rex/text/checksum.rb
rex-text-0.2.48 lib/rex/text/checksum.rb
rex-text-0.2.47 lib/rex/text/checksum.rb
rex-text-0.2.46 lib/rex/text/checksum.rb
rex-text-0.2.45 lib/rex/text/checksum.rb
rex-text-0.2.44 lib/rex/text/checksum.rb
rex-text-0.2.43 lib/rex/text/checksum.rb
rex-text-0.2.42 lib/rex/text/checksum.rb
rex-text-0.2.41 lib/rex/text/checksum.rb
rex-text-0.2.40 lib/rex/text/checksum.rb