<commit_before># Base58GMP
# Copyright (c) 2011-2016 <NAME>
# http://johnwang.com
# Distributed under the MIT license as included with this gem.

require 'digest/md5'
require 'gmp'

class Base58GMP
  VERSION = '1.0.1'

  ALPHABETS = {
    bitcoin: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz',
    flickr:  '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ',
    ripple:  'rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz',
    gmp:     '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv'
  }

  DEFAULT_ALPHABET = :flickr
  GMP_ALPHABET = :gmp
  BASE58_LENGTH_MD5 = 22

  def self.integer_to_base58(integer, alphabet = DEFAULT_ALPHABET)
    base58 = integer.is_a?(GMP::Z) \
           ? integer.to_s(58) \
           : GMP::Z(integer).to_s(58)

    normalize_alphabet(alphabet) == GMP_ALPHABET \
      ? base58 \
      : from_to(base58, GMP_ALPHABET, alphabet)
  end

  def self.base58_to_integer(base58, alphabet = DEFAULT_ALPHABET)
    unless base58.is_a? String
      fail ArgumentError, 'Base58 argument is not a string.'
    end

    unless normalize_alphabet(alphabet) == GMP_ALPHABET
      base58 = from_to(base58, alphabet, GMP_ALPHABET)
    end

    GMP::Z.new(base58, 58)
  end

  def self.from_to(base58, from_alphabet, to_alphabet)
    unless base58.is_a? String
      fail ArgumentError, 'Base58 argument is not a string.'
    end

    from_digits = alphabet_digits from_alphabet
    to_digits = alphabet_digits to_alphabet

    from_digits != to_digits \
      ? base58.tr(from_digits, to_digits) \
      : base58
  end

  def self.normalize_alphabet(alphabet)
    alphabet.to_sym.downcase
  end

  def self.alphabet_digits(alphabet)
    alphabet = normalize_alphabet alphabet

    unless ALPHABETS.key? alphabet
      fail ArgumentError, "Alphabet is invalid: #{alphabet}"
    end

    return ALPHABETS[alphabet]
  end

  def self.md5_base58(data, alphabet = DEFAULT_ALPHABET, opts = {})
    base58 = integer_to_base58(Digest::MD5.hexdigest(data).hex, alphabet)

    opts.key?(:pad) && opts[:pad] \
      ? base58.rjust(BASE58_LENGTH_MD5, alphabet_digits(alphabet)[0]) \
      : base58
  end

  class << self
    alias encode integer_to_base58
    alias decode base58_to_integer
    alias md5 md5_base58
  end
end<commit_msg>update style<commit_after># Base58GMP
# Copyright (c) 2011-2016 <NAME>
# http://johnwang.com
# Distributed under the MIT license as included with this gem.

require 'digest/md5'
require 'gmp'

class Base58GMP
  VERSION = '1.0.1'

  ALPHABETS = {
    bitcoin: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz',
    flickr:  '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ',
    ripple:  'rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz',
    gmp:     '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv'
  }

  DEFAULT_ALPHABET = :flickr
  GMP_ALPHABET = :gmp
  BASE58_LENGTH_MD5 = 22

  def self.integer_to_base58(integer, alphabet = DEFAULT_ALPHABET)
    base58 = integer.is_a?(GMP::Z) ? integer.to_s(58) : GMP::Z(integer).to_s(58)

    return base58 if normalize_alphabet(alphabet) == GMP_ALPHABET
    from_to(base58, GMP_ALPHABET, alphabet)
  end

  def self.base58_to_integer(base58, alphabet = DEFAULT_ALPHABET)
    unless base58.is_a? String
      fail ArgumentError, 'Base58 argument is not a string.'
    end

    unless normalize_alphabet(alphabet) == GMP_ALPHABET
      base58 = from_to(base58, alphabet, GMP_ALPHABET)
    end

    GMP::Z.new(base58, 58)
  end

  def self.from_to(base58, from_alphabet, to_alphabet)
    unless base58.is_a? String
      fail ArgumentError, 'Base58 argument is not a string.'
    end

    from_digits = alphabet_digits from_alphabet
    to_digits = alphabet_digits to_alphabet

    return base58.tr(from_digits, to_digits) if from_digits != to_digits
    base58
  end

  def self.normalize_alphabet(alphabet)
    alphabet.to_sym.downcase
  end

  def self.alphabet_digits(alphabet)
    alphabet = normalize_alphabet alphabet

    unless ALPHABETS.key? alphabet
      fail ArgumentError, "Alphabet is invalid: #{alphabet}"
    end

    return ALPHABETS[alphabet]
  end

  def self.md5_base58(data, alphabet = DEFAULT_ALPHABET, opts = {})
    base58 = integer_to_base58(Digest::MD5.hexdigest(data).hex, alphabet)

    if opts.key?(:pad) && opts[:pad]
      return base58.rjust(BASE58_LENGTH_MD5, alphabet_digits(alphabet)[0])
    end
    base58
  end

  class << self
    alias encode integer_to_base58
    alias decode base58_to_integer
    alias md5 md5_base58
  end
end
{'fraction_non_alphanumeric': 0.08500330323717242, 'fraction_numerical': 0.05285179475886369, 'mean_word_length': 3.8891280947255114, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4355972', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1707, 'n_words': 325}