<commit_before>#include "conversions.h"

namespace ffx {

bool BitMask(const mpz_class & in,
             uint32_t in_len_in_bits,
             uint32_t start_bit,
             uint32_t end_bit,
             mpz_class * out) {
  (*out) = in;
  (*out) = (*out) >> (in_len_in_bits - end_bit - 1);
  mpz_class modulus;
  mpz_ui_pow_ui(modulus.get_mpz_t(), 2, (end_bit - start_bit + 1));
  (*out) = (*out) % modulus;

  return true;
}

bool MpzClassToBase256(const mpz_class & in,
                       uint32_t out_len_in_bytes,
                       unsigned char * out) {

  size_t written_bytes = 0;
  mpz_export(out,             // void *rop
             &written_bytes,  // size_t *countp
             1,               // int order
             1,               // size_t size
             1,               // int endian
             0,               // size_t nails
             in.get_mpz_t()); // const mpz_t op

  uint32_t delta = out_len_in_bytes - written_bytes;
  if (delta > 0) {
    for (int32_t i = out_len_in_bytes-1; i>=delta; --i) {
      out[i] = out[i-delta];
    }
    for (int32_t i = 0; i < delta; i++) {
      out[i] = 0x00;
    }
  }

  return true;
}

bool Base256ToMpzClass(unsigned char * in,
                       uint32_t in_len_in_bytes,
                       mpz_class * out) {

  mpz_import((*out).get_mpz_t(), // mpz_t rop
             in_len_in_bytes,    // size_t count
             1,                  // int order
             1,                  // size_t size
             1,                  // int endian
             0,                  // size_t nails
             in);                // const void *op

  return true;
}

bool Base16ToBase256(const std::string & in,
                     uint32_t out_len_in_bytes,
                     unsigned char * out) {

  mpz_class tmp = mpz_class(in, 16);
  MpzClassToBase256(tmp, out_len_in_bytes, out);

  return true;
}

} // namespace ffx
<commit_msg>Issue #9: use memmove/memset<commit_after>#include "conversions.h"

namespace ffx {

bool BitMask(const mpz_class & in,
             uint32_t in_len_in_bits,
             uint32_t start_bit,
             uint32_t end_bit,
             mpz_class * out) {
  (*out) = in;
  (*out) = (*out) >> (in_len_in_bits - end_bit - 1);
  mpz_class modulus;
  mpz_ui_pow_ui(modulus.get_mpz_t(), 2, (end_bit - start_bit + 1));
  (*out) = (*out) % modulus;

  return true;
}

bool MpzClassToBase256(const mpz_class & in,
                       uint32_t out_len_in_bytes,
                       unsigned char * out) {

  size_t written_bytes = 0;
  mpz_export(out,             // void *rop
             &written_bytes,  // size_t *countp
             1,               // int order
             1,               // size_t size
             1,               // int endian
             0,               // size_t nails
             in.get_mpz_t()); // const mpz_t op

  // If mpz_export writes less bytes than specified
  // by out_len_in_bytes, then we need to padd out
  // with zeros.
  uint32_t delta = out_len_in_bytes - written_bytes;
  if (delta > 0) {
    memmove(out + delta, out, out_len_in_bytes - delta);
    memset(out, 0, delta);
  }

  return true;
}

bool Base256ToMpzClass(unsigned char * in,
                       uint32_t in_len_in_bytes,
                       mpz_class * out) {

  mpz_import((*out).get_mpz_t(), // mpz_t rop
             in_len_in_bytes,    // size_t count
             1,                  // int order
             1,                  // size_t size
             1,                  // int endian
             0,                  // size_t nails
             in);                // const void *op

  return true;
}

bool Base16ToBase256(const std::string & in,
                     uint32_t out_len_in_bytes,
                     unsigned char * out) {

  mpz_class tmp = mpz_class(in, 16);
  MpzClassToBase256(tmp, out_len_in_bytes, out);

  return true;
}

} // namespace ffx

{'fraction_non_alphanumeric': 0.10104087331810103, 'fraction_numerical': 0.024625539477024627, 'mean_word_length': 1.4039048200122026, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5593821', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1305, 'n_words': 305}