<commit_before>// The MIT License (MIT)

// Copyright (c) 2013 lailongwei<<EMAIL>>
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy of 
// this software and associated documentation files (the "Software"), to deal in 
// the Software without restriction, including without limitation the rights to 
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 
// the Software, and to permit persons to whom the Software is furnished to do so, 
// subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all 
// copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include "llbc/common/Export.h"
#include "llbc/common/BeforeIncl.h"

#include "llbc/core/file/File.h"

#include "llbc/core/utils/Util_Text.h"
#include "llbc/core/utils/Util_MD5.h"

#if LLBC_TARGET_PLATFORM_WIN32
#pragma warning(disable:4996)
#endif

__LLBC_NS_BEGIN

#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
LLBC_MD5::MD5GroupDigest::MD5GroupDigest(uint32 a, uint32 b, uint32 c, uint32 d)
{
    SetInfo(a, b, c, d);
}

uint32 LLBC_MD5::MD5GroupDigest::GetA() const
{
    return _val.sVal.a;
}

void LLBC_MD5::MD5GroupDigest::SetA(uint32 a)
{
    _val.sVal.a = a;
}

uint32 LLBC_MD5::MD5GroupDigest::GetB() const
{
    return _val.sVal.b;
}

void LLBC_MD5::MD5GroupDigest::SetB(uint32 b)
{
    _val.sVal.b = b;
}

uint32 LLBC_MD5::MD5GroupDigest::GetC() const
{
    return _val.sVal.c;
}

void LLBC_MD5::MD5GroupDigest::SetC(uint32 c)
{
    _val.sVal.c = c;
}

uint32 LLBC_MD5::MD5GroupDigest::GetD() const
{
    return _val.sVal.d;
}

void LLBC_MD5::MD5GroupDigest::SetD(uint32 d)
{
    _val.sVal.d = d;
}

void LLBC_MD5::MD5GroupDigest::SetInfo(uint32 a, uint32 b, uint32 c, uint32 d)
{
    SetA(a);
    SetB(b);
    SetC(c);
    SetD(d);
}

LLBC_String LLBC_MD5::MD5GroupDigest::ToString() const
{
    char buf[64];
    sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
        _val.byteVal[0], _val.byteVal[1], _val.byteVal[2], _val.byteVal[3],
        _val.byteVal[4], _val.byteVal[5], _val.byteVal[6], _val.byteVal[7],
        _val.byteVal[8], _val.byteVal[9], _val.byteVal[10], _val.byteVal[11],
        _val.byteVal[12], _val.byteVal[13], _val.byteVal[14], _val.byteVal[15]);

    return buf;
}

LLBC_MD5::MD5GroupDigest &LLBC_MD5::MD5GroupDigest::operator +=(const LLBC_MD5::MD5GroupDigest &right)
{
    SetA(GetA() + right.GetA());
    SetB(GetB() + right.GetB());
    SetC(GetC() + right.GetC());
    SetD(GetD() + right.GetD());

    return *this;
}

const uint32 LLBC_MD5::MD5Group::Ti[64 + 1] = {
    0,
    (uint32)(4294967296l * fabs(sin( 1.0))), (uint32)(4294967296l * fabs(sin( 2.0))), 
    (uint32)(4294967296l * fabs(sin( 3.0))), (uint32)(4294967296l * fabs(sin( 4.0))),
    (uint32)(4294967296l * fabs(sin( 5.0))), (uint32)(4294967296l * fabs(sin( 6.0))), 
    (uint32)(4294967296l * fabs(sin( 7.0))), (uint32)(4294967296l * fabs(sin( 8.0))),
    (uint32)(4294967296l * fabs(sin( 9.0))), (uint32)(4294967296l * fabs(sin(10.0))), 
    (uint32)(4294967296l * fabs(sin(11.0))), (uint32)(4294967296l * fabs(sin(12.0))),
    (uint32)(4294967296l * fabs(sin(13.0))), (uint32)(4294967296l * fabs(sin(14.0))), 
    (uint32)(4294967296l * fabs(sin(15.0))), (uint32)(4294967296l * fabs(sin(16.0))),
    (uint32)(4294967296l * fabs(sin(17.0))), (uint32)(4294967296l * fabs(sin(18.0))), 
    (uint32)(4294967296l * fabs(sin(19.0))), (uint32)(4294967296l * fabs(sin(20.0))),
    (uint32)(4294967296l * fabs(sin(21.0))), (uint32)(4294967296l * fabs(sin(22.0))), 
    (uint32)(4294967296l * fabs(sin(23.0))), (uint32)(4294967296l * fabs(sin(24.0))),
    (uint32)(4294967296l * fabs(sin(25.0))), (uint32)(4294967296l * fabs(sin(26.0))), 
    (uint32)(4294967296l * fabs(sin(27.0))), (uint32)(4294967296l * fabs(sin(28.0))),
    (uint32)(4294967296l * fabs(sin(29.0))), (uint32)(4294967296l * fabs(sin(30.0))), 
    (uint32)(4294967296l * fabs(sin(31.0))), (uint32)(4294967296l * fabs(sin(32.0))),
    (uint32)(4294967296l * fabs(sin(33.0))), (uint32)(4294967296l * fabs(sin(34.0))), 
    (uint32)(4294967296l * fabs(sin(35.0))), (uint32)(4294967296l * fabs(sin(36.0))),
    (uint32)(4294967296l * fabs(sin(37.0))), (uint32)(4294967296l * fabs(sin(38.0))), 
    (uint32)(4294967296l * fabs(sin(39.0))), (uint32)(4294967296l * fabs(sin(40.0))),
    (uint32)(4294967296l * fabs(sin(41.0))), (uint32)(4294967296l * fabs(sin(42.0))), 
    (uint32)(4294967296l * fabs(sin(43.0))), (uint32)(4294967296l * fabs(sin(44.0))),
    (uint32)(4294967296l * fabs(sin(45.0))), (uint32)(4294967296l * fabs(sin(46.0))), 
    (uint32)(4294967296l * fabs(sin(47.0))), (uint32)(4294967296l * fabs(sin(48.0))),
    (uint32)(4294967296l * fabs(sin(49.0))), (uint32)(4294967296l * fabs(sin(50.0))), 
    (uint32)(4294967296l * fabs(sin(51.0))), (uint32)(4294967296l * fabs(sin(52.0))),
    (uint32)(4294967296l * fabs(sin(53.0))), (uint32)(4294967296l * fabs(sin(54.0))), 
    (uint32)(4294967296l * fabs(sin(55.0))), (uint32)(4294967296l * fabs(sin(56.0))),
    (uint32)(4294967296l * fabs(sin(57.0))), (uint32)(4294967296l * fabs(sin(58.0))), 
    (uint32)(4294967296l * fabs(sin(59.0))), (uint32)(4294967296l * fabs(sin(60.0))),
    (uint32)(4294967296l * fabs(sin(61.0))), (uint32)(4294967296l * fabs(sin(62.0))), 
    (uint32)(4294967296l * fabs(sin(63.0))), (uint32)(4294967296l * fabs(sin(64.0)))
};

LLBC_MD5::MD5Group::MD5Group(const void *buf, size_t pos)
{
    _buf = LLBC_Malloc(char, GROUP_SIZE);
    memcpy(_buf, reinterpret_cast<const char *>(buf) + pos, GROUP_SIZE);
}

LLBC_MD5::MD5Group::~MD5Group()
{
    LLBC_XFree(_buf);
}

void LLBC_MD5::MD5Group::GenerateDigest(LLBC_MD5::MD5GroupDigest &digest)
{
    uint32 a = digest.GetA();
    uint32 b = digest.GetB();
    uint32 c = digest.GetC();
    uint32 d = digest.GetD();

    // Loop 1:
    FF(a, b, c, d, GetSubGroupValue( 0), S11, Ti[1]);
    FF(d, a, b, c, GetSubGroupValue( 1), S12, Ti[2]);
    FF(c, d, a, b, GetSubGroupValue( 2), S13, Ti[3]);
    FF(b, c, d, a, GetSubGroupValue( 3), S14, Ti[4]);
    FF(a, b, c, d, GetSubGroupValue( 4), S11, Ti[5]);
    FF(d, a, b, c, GetSubGroupValue( 5), S12, Ti[6]);
    FF(c, d, a, b, GetSubGroupValue( 6), S13, Ti[7]);
    FF(b, c, d, a, GetSubGroupValue( 7), S14, Ti[8]);
    FF(a, b, c, d, GetSubGroupValue( 8), S11, Ti[9]);<commit_msg>Fix compile warnings<commit_after>// The MIT License (MIT)

// Copyright (c) 2013 lailongwei<<EMAIL>>
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy of 
// this software and associated documentation files (the "Software"), to deal in 
// the Software without restriction, including without limitation the rights to 
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 
// the Software, and to permit persons to whom the Software is furnished to do so, 
// subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all 
// copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include "llbc/common/Export.h"
#include "llbc/common/BeforeIncl.h"

#include "llbc/core/file/File.h"

#include "llbc/core/utils/Util_Text.h"
#include "llbc/core/utils/Util_MD5.h"

#if LLBC_TARGET_PLATFORM_WIN32
#pragma warning(disable:4996)
#endif

__LLBC_NS_BEGIN

#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
LLBC_MD5::MD5GroupDigest::MD5GroupDigest(uint32 a, uint32 b, uint32 c, uint32 d)
{
    SetInfo(a, b, c, d);
}

uint32 LLBC_MD5::MD5GroupDigest::GetA() const
{
    return _val.sVal.a;
}

void LLBC_MD5::MD5GroupDigest::SetA(uint32 a)
{
    _val.sVal.a = a;
}

uint32 LLBC_MD5::MD5GroupDigest::GetB() const
{
    return _val.sVal.b;
}

void LLBC_MD5::MD5GroupDigest::SetB(uint32 b)
{
    _val.sVal.b = b;
}

uint32 LLBC_MD5::MD5GroupDigest::GetC() const
{
    return _val.sVal.c;
}

void LLBC_MD5::MD5GroupDigest::SetC(uint32 c)
{
    _val.sVal.c = c;
}

uint32 LLBC_MD5::MD5GroupDigest::GetD() const
{
    return _val.sVal.d;
}

void LLBC_MD5::MD5GroupDigest::SetD(uint32 d)
{
    _val.sVal.d = d;
}

void LLBC_MD5::MD5GroupDigest::SetInfo(uint32 a, uint32 b, uint32 c, uint32 d)
{
    SetA(a);
    SetB(b);
    SetC(c);
    SetD(d);
}

LLBC_String LLBC_MD5::MD5GroupDigest::ToString() const
{
    char buf[64];
    sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
        _val.byteVal[0], _val.byteVal[1], _val.byteVal[2], _val.byteVal[3],
        _val.byteVal[4], _val.byteVal[5], _val.byteVal[6], _val.byteVal[7],
        _val.byteVal[8], _val.byteVal[9], _val.byteVal[10], _val.byteVal[11],
        _val.byteVal[12], _val.byteVal[13], _val.byteVal[14], _val.byteVal[15]);

    return buf;
}

LLBC_MD5::MD5GroupDigest &LLBC_MD5::MD5GroupDigest::operator +=(const LLBC_MD5::MD5GroupDigest &right)
{
    SetA(GetA() + right.GetA());
    SetB(GetB() + right.GetB());
    SetC(GetC() + right.GetC());
    SetD(GetD() + right.GetD());

    return *this;
}

const uint32 LLBC_MD5::MD5Group::Ti[64 + 1] = {
    0,
    (uint32)(4294967296llu * fabs(sin( 1.0))), (uint32)(4294967296llu * fabs(sin( 2.0))), 
    (uint32)(4294967296llu * fabs(sin( 3.0))), (uint32)(4294967296llu * fabs(sin( 4.0))),
    (uint32)(4294967296llu * fabs(sin( 5.0))), (uint32)(4294967296llu * fabs(sin( 6.0))), 
    (uint32)(4294967296llu * fabs(sin( 7.0))), (uint32)(4294967296llu * fabs(sin( 8.0))),
    (uint32)(4294967296llu * fabs(sin( 9.0))), (uint32)(4294967296llu * fabs(sin(10.0))), 
    (uint32)(4294967296llu * fabs(sin(11.0))), (uint32)(4294967296llu * fabs(sin(12.0))),
    (uint32)(4294967296llu * fabs(sin(13.0))), (uint32)(4294967296llu * fabs(sin(14.0))), 
    (uint32)(4294967296llu * fabs(sin(15.0))), (uint32)(4294967296llu * fabs(sin(16.0))),
    (uint32)(4294967296llu * fabs(sin(17.0))), (uint32)(4294967296llu * fabs(sin(18.0))), 
    (uint32)(4294967296llu * fabs(sin(19.0))), (uint32)(4294967296llu * fabs(sin(20.0))),
    (uint32)(4294967296llu * fabs(sin(21.0))), (uint32)(4294967296llu * fabs(sin(22.0))), 
    (uint32)(4294967296llu * fabs(sin(23.0))), (uint32)(4294967296llu * fabs(sin(24.0))),
    (uint32)(4294967296llu * fabs(sin(25.0))), (uint32)(4294967296llu * fabs(sin(26.0))), 
    (uint32)(4294967296llu * fabs(sin(27.0))), (uint32)(4294967296llu * fabs(sin(28.0))),
    (uint32)(4294967296llu * fabs(sin(29.0))), (uint32)(4294967296llu * fabs(sin(30.0))), 
    (uint32)(4294967296llu * fabs(sin(31.0))), (uint32)(4294967296llu * fabs(sin(32.0))),
    (uint32)(4294967296llu * fabs(sin(33.0))), (uint32)(4294967296llu * fabs(sin(34.0))), 
    (uint32)(4294967296llu * fabs(sin(35.0))), (uint32)(4294967296llu * fabs(sin(36.0))),
    (uint32)(4294967296llu * fabs(sin(37.0))), (uint32)(4294967296llu * fabs(sin(38.0))), 
    (uint32)(4294967296llu * fabs(sin(39.0))), (uint32)(4294967296llu * fabs(sin(40.0))),
    (uint32)(4294967296llu * fabs(sin(41.0))), (uint32)(4294967296llu * fabs(sin(42.0))), 
    (uint32)(4294967296llu * fabs(sin(43.0))), (uint32)(4294967296llu * fabs(sin(44.0))),
    (uint32)(4294967296llu * fabs(sin(45.0))), (uint32)(4294967296llu * fabs(sin(46.0))), 
    (uint32)(4294967296llu * fabs(sin(47.0))), (uint32)(4294967296llu * fabs(sin(48.0))),
    (uint32)(4294967296llu * fabs(sin(49.0))), (uint32)(4294967296llu * fabs(sin(50.0))), 
    (uint32)(4294967296llu * fabs(sin(51.0))), (uint32)(4294967296llu * fabs(sin(52.0))),
    (uint32)(4294967296llu * fabs(sin(53.0))), (uint32)(4294967296llu * fabs(sin(54.0))), 
    (uint32)(4294967296llu * fabs(sin(55.0))), (uint32)(4294967296llu * fabs(sin(56.0))),
    (uint32)(4294967296llu * fabs(sin(57.0))), (uint32)(4294967296llu * fabs(sin(58.0))), 
    (uint32)(4294967296llu * fabs(sin(59.0))), (uint32)(4294967296llu * fabs(sin(60.0))),
    (uint32)(4294967296llu * fabs(sin(61.0))), (uint32)(4294967296llu * fabs(sin(62.0))), 
    (uint32)(4294967296llu * fabs(sin(63.0))), (uint32)(4294967296llu * fabs(sin(64.0)))
};

LLBC_MD5::MD5Group::MD5Group(const void *buf, size_t pos)
{
    _buf = LLBC_Malloc(char, GROUP_SIZE);
    memcpy(_buf, reinterpret_cast<const char *>(buf) + pos, GROUP_SIZE);
}

LLBC_MD5::MD5Group::~MD5Group()
{
    LLBC_XFree(_buf);
}

void LLBC_MD5::MD5Group::GenerateDigest(LLBC_MD5::MD5GroupDigest &digest)
{
    uint32 a = digest.GetA();
    uint32 b = digest.GetB();
    uint32 c = digest.GetC();
    uint32 d = digest.GetD();

    // Loop 1:
    FF(a, b, c, d, GetSubGroupValue( 0), S11, Ti[1]);
    FF(d, a, b, c, GetSubGroupValue( 1), S12, Ti[2]);
    FF(c, d, a, b, GetSubGroupValue( 2), S13, Ti[3]);
    FF(b, c, d, a, GetSubGroupValue( 3), S14, Ti[4]);
    FF(a, b, c, d, GetSubGroupValue( 4), S11, Ti[5]);
    FF(d, a, b, c, GetSubGroupValue( 5), S12, Ti[6]);
    FF(c, d, a, b, GetSubGroupValue( 6), S13, Ti[7]);
    FF(b, c, d, a, GetSubGroupValue( 7), S14, Ti[8]);
    FF(a, b, c, d, GetSubGroupValue( 8), S11, Ti[9]);
{'fraction_non_alphanumeric': 0.1927049476345251, 'fraction_numerical': 0.1652582159624413, 'mean_word_length': 4.686242299794661, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '342012', 'n_tokens_mistral': 7275, 'n_tokens_neox': 6004, 'n_words': 1093}