<commit_before>require 'openssl'

module Encrypt
  refine String do
    def encrypt key
      cipher = OpenSSL::Cipher::AES256.new(:CTR)
      cipher.encrypt
      iv = cipher.random_iv
      salt = OpenSSL::Random.random_bytes(16)
      cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 20000, 32)
      salt << iv << cipher.update(self) << cipher.final
    end

    def decrypt key
      return nil unless self.bytesize > 32
      cipher = OpenSSL::Cipher::AES256.new(:CTR)
      cipher.decrypt
      salt = self.byteslice(0..15)
      cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 20000, 32)
      cipher.iv = self.byteslice(16..31)
      cipher.update(self.byteslice(32..-1)) << cipher.final
    end
  end
end<commit_msg>Use if statement instead of return.<commit_after>require 'openssl'

module Encrypt
  refine String do
    def encrypt key
      cipher = OpenSSL::Cipher::AES256.new(:CTR)
      cipher.encrypt
      iv = cipher.random_iv
      salt = OpenSSL::Random.random_bytes(16)
      cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 20000, 32)
      salt << iv << cipher.update(self) << cipher.final
    end

    def decrypt key
      if self.bytesize > 32
        cipher = OpenSSL::Cipher::AES256.new(:CTR)
        cipher.decrypt
        salt = self.byteslice(0..15)
        cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 20000, 32)
        cipher.iv = self.byteslice(16..31)
        cipher.update(self.byteslice(32..-1)) << cipher.final
      else
        nil
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11799217731421122, 'fraction_numerical': 0.05215123859191656, 'mean_word_length': 2.6547619047619047, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 5, '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': '6366436', 'n_tokens_mistral': 615, 'n_tokens_neox': 534, 'n_words': 109}