<commit_before>require 'openssl'

require 'cmac/version'

class CMAC
  Exception = Class.new(StandardError)
  ZeroBlock = "\0" * 16
  ConstantBlock = ("\0" * 15) + "\x87"

  def initialize(key)
    @key = _derive_key(key.b)
    @key1, @key2 = _generate_subkeys(@key)
  end

  def inspect
    "#<CMAC:#{object_id.to_s(16)}>"
  end

  def sign(message, truncate = 16)
    raise CMAC::Exception.new('Tag cannot be greater than maximum (16 bytes)') if truncate > 16
    raise CMAC::Exception.new('Tag cannot be less than minimum (8 bytes)') if truncate < 8

    message = message.b

    if _needs_padding?(message)
      message = _pad_message(message)
      final_block = @key2
    else
      final_block = @key1
    end

    last_ciphertext = ZeroBlock
    count = message.length / 16
    range = Range.new(0, count - 1)
    blocks = range.map { |i| message.slice(16 * i, 16) }
    blocks.each_with_index do |block, i|
      if i == range.last
        block = _xor(final_block, block)
      end

      block = _xor(block, last_ciphertext)
      last_ciphertext = _encrypt_block(@key, block)<commit_msg>Include the leading 0x in the object id<commit_after>require 'openssl'

require 'cmac/version'

class CMAC
  Exception = Class.new(StandardError)
  ZeroBlock = "\0" * 16
  ConstantBlock = ("\0" * 15) + "\x87"

  def initialize(key)
    @key = _derive_key(key.b)
    @key1, @key2 = _generate_subkeys(@key)
  end

  def inspect
    "#<CMAC:0x#{object_id.to_s(16)}>"
  end

  def sign(message, truncate = 16)
    raise CMAC::Exception.new('Tag cannot be greater than maximum (16 bytes)') if truncate > 16
    raise CMAC::Exception.new('Tag cannot be less than minimum (8 bytes)') if truncate < 8

    message = message.b

    if _needs_padding?(message)
      message = _pad_message(message)
      final_block = @key2
    else
      final_block = @key1
    end

    last_ciphertext = ZeroBlock
    count = message.length / 16
    range = Range.new(0, count - 1)
    blocks = range.map { |i| message.slice(16 * i, 16) }
    blocks.each_with_index do |block, i|
      if i == range.last
        block = _xor(final_block, block)
      end

      block = _xor(block, last_ciphertext)
      last_ciphertext = _encrypt_block(@key, block)
{'fraction_non_alphanumeric': 0.11759425493716337, 'fraction_numerical': 0.027827648114901255, 'mean_word_length': 2.9946236559139785, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1006291', 'n_tokens_mistral': 820, 'n_tokens_neox': 760, 'n_words': 208}