<commit_before># encoding: UTF-8

require 'archive/support/integer'
require 'archive/support/io-like'
require 'archive/support/time'
require 'archive/support/zlib'
require 'archive/zip/codec'

module Archive; class Zip; module Codec
  # Archive::Zip::Codec::TraditionalEncryption is a handle for the traditional
  # encryption codec.
  class TraditionalEncryption
    # Archive::Zip::Codec::TraditionalEncryption::Base provides some basic
    # methods which are shared between
    # Archive::Zip::Codec::TraditionalEncryption::Encrypt and
    # Archive::Zip::Codec::TraditionalEncryption::Decrypt.
    #
    # Do not use this class directly.
    class Base
      # Creates a new instance of this class.  _io_ must be an IO-like object to
      # be used as a delegate for IO operations.  _password_ should be the
      # encryption key.  _mtime_ must be the last modified time of the entry to
      # be encrypted/decrypted.
      def initialize(io, password, mtime)
        @io = io
        @password = password.nil? ? '' : password
        @mtime = mtime
        initialize_keys
      end

      protected

      # The delegate IO-like object.
      attr_reader :io
      # The encryption key.
      attr_reader :password
      # The last modified time of the entry being encrypted.  This is used in
      # the entryption header as a way to check the password.
      attr_reader :mtime

      private

      # Initializes the keys used for encrypting/decrypting data by setting the
      # keys to well known values and then processing them with the password.
      def initialize_keys
        @key0 = 0x12345678
        @key1 = 0x23456789
        @key2 = 0x34567890
        @password.each_byte { |byte| update_keys(byte.chr) }
        nil
      end

      # Updates the keys following the ZIP specification using _char_, which
      # must be a single byte String.
      def update_keys(char)
        # For some reason not explained in the ZIP specification but discovered
        # in the source for InfoZIP, the old CRC value must first have its bits
        # flipped before processing.  The new CRC value must have its bits
        # flipped as well for storage and later use.  This applies to the
        # handling of @key0 and @key2.
        #
        # NOTE: XOR'ing with 0xffffffff is used instead of simple bit negation
        # in case this is run on a platform with a native integer size of
        # something other than 32 bits.
        @key0 = Zlib.crc32(char, @key0 ^ 0xffffffff) ^ 0xffffffff
        @key1 = ((@key1 + (@key0 & 0xff)) * 134775813 + 1) & 0xffffffff
        @key2 = Zlib.crc32((@key1 >> 24).chr, @key2 ^ 0xffffffff) ^ 0xffffffff
        nil
      end

      # Returns the next decryption byte based on the current keys.
      def decrypt_byte
        temp = (@key2 | 2) & 0x0000ffff
        ((temp * (temp ^ 1)) >> 8) & 0x000000ff<commit_msg>Remove unecessary 64-bit binary not workaround<commit_after># encoding: UTF-8

require 'archive/support/integer'
require 'archive/support/io-like'
require 'archive/support/time'
require 'archive/support/zlib'
require 'archive/zip/codec'

module Archive; class Zip; module Codec
  # Archive::Zip::Codec::TraditionalEncryption is a handle for the traditional
  # encryption codec.
  class TraditionalEncryption
    # Archive::Zip::Codec::TraditionalEncryption::Base provides some basic
    # methods which are shared between
    # Archive::Zip::Codec::TraditionalEncryption::Encrypt and
    # Archive::Zip::Codec::TraditionalEncryption::Decrypt.
    #
    # Do not use this class directly.
    class Base
      # Creates a new instance of this class.  _io_ must be an IO-like object to
      # be used as a delegate for IO operations.  _password_ should be the
      # encryption key.  _mtime_ must be the last modified time of the entry to
      # be encrypted/decrypted.
      def initialize(io, password, mtime)
        @io = io
        @password = password.nil? ? '' : password
        @mtime = mtime
        initialize_keys
      end

      protected

      # The delegate IO-like object.
      attr_reader :io
      # The encryption key.
      attr_reader :password
      # The last modified time of the entry being encrypted.  This is used in
      # the entryption header as a way to check the password.
      attr_reader :mtime

      private

      # Initializes the keys used for encrypting/decrypting data by setting the
      # keys to well known values and then processing them with the password.
      def initialize_keys
        @key0 = 0x12345678
        @key1 = 0x23456789
        @key2 = 0x34567890
        @password.each_byte { |byte| update_keys(byte.chr) }
        nil
      end

      # Updates the keys following the ZIP specification using _char_, which
      # must be a single byte String.
      def update_keys(char)
        # For some reason not explained in the ZIP specification but discovered
        # in the source for InfoZIP, the old CRC value must first have its bits
        # flipped before processing.  The new CRC value must have its bits
        # flipped as well for storage and later use.  This applies to the
        # handling of @key0 and @key2.
        @key0 = ~Zlib.crc32(char, ~@key0)
        @key1 = ((@key1 + (@key0 & 0xff)) * 134775813 + 1) & 0xffffffff
        @key2 = ~Zlib.crc32((@key1 >> 24).chr, ~@key2)
        nil
      end

      # Returns the next decryption byte based on the current keys.
      def decrypt_byte
        temp = (@key2 | 2) & 0x0000ffff
        ((temp * (temp ^ 1)) >> 8) & 0x000000ff
{'fraction_non_alphanumeric': 0.07436823104693141, 'fraction_numerical': 0.028700361010830323, 'mean_word_length': 2.5748387096774192, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 7, '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': '1077505', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1542, 'n_words': 608}