<commit_before><?php

namespace AEngine\Orchid\Misc;

use AEngine\Orchid\App;

class Crypta
{
    /**
     * Encrypt transmitted string
     *
     * @param string $input
     *
     * @return string
     */
    public static function encrypt($input)
    {
        return base64_encode(static::crypt($input));
    }

    /**
     * Helper method to work with a string line
     *
     * @param string $input
     *
     * @return string
     */
    protected static function crypt($input)
    {
        $salt = md5(App::getInstance()->getSecret());
        $len = mb_strlen($input);
        $gamma = '';
        $n = $len > 100 ? 8 : 2;
        while (mb_strlen($gamma) < $len) {
            $gamma .= substr(pack('H*', sha1($gamma . $salt)), 0, $n);
        }

        return $input ^ $gamma;
    }

    /**
     * Decrypt passed string
     *
     * @param string $input
     *
     * @return string
     */
    public static function decrypt($input)
    {
        return static::crypt(base64_decode($input));
    }

    /**
     * Generate hash sum for a row
     *
     * @param string $string
     *
     * @return string
     */
    public static function hash($string)
    {
        $salt = substr(hash('whirlpool', uniqid(rand() . App::getInstance()->getSecret(), true)), 0, 12);
        $hash = hash('whirlpool', $salt . $string);
        $saltPos = (mb_strlen($string) >= mb_strlen($hash) ? mb_strlen($hash) : mb_strlen($string));

        return substr($hash, 0, $saltPos) . $salt . substr($hash, $saltPos);
    }

    /**
     * Check string against the hash sum
     *
     * @param string $string
     * @param string $hashString
     *
     * @return bool
     */
    public static function check($string, $hashString)
    {
        $saltPos = (mb_strlen($string) >= mb_strlen($hashString) ? mb_strlen($hashString) : mb_strlen($string));
        $salt = substr($hashString, $saltPos, 12);
        $hash = hash('whirlpool', $salt . $string);

        return $hashString == substr($hash, 0, $saltPos) . $salt . substr($hash, $saltPos);
    }
}
<commit_msg>security rand<commit_after><?php

namespace AEngine\Orchid\Misc;

use AEngine\Orchid\App;

class Crypta
{
    /**
     * Encrypt transmitted string
     *
     * @param string $input
     *
     * @return string
     */
    public static function encrypt($input)
    {
        return base64_encode(static::crypt($input));
    }

    /**
     * Helper method to work with a string line
     *
     * @param string $input
     *
     * @return string
     */
    protected static function crypt($input)
    {
        $salt = md5(App::getInstance()->getSecret());
        $len = mb_strlen($input);
        $gamma = '';
        $n = $len > 100 ? 8 : 2;
        while (mb_strlen($gamma) < $len) {
            $gamma .= substr(pack('H*', sha1($gamma . $salt)), 0, $n);
        }

        return $input ^ $gamma;
    }

    /**
     * Decrypt passed string
     *
     * @param string $input
     *
     * @return string
     */
    public static function decrypt($input)
    {
        return static::crypt(base64_decode($input));
    }

    /**
     * Generate hash sum for a row
     *
     * @param string $string
     *
     * @return string
     */
    public static function hash($string)
    {
        $salt = substr(hash('whirlpool', uniqid(mt_rand() . App::getInstance()->getSecret(), true)), 0, 12);
        $hash = hash('whirlpool', $salt . $string);
        $saltPos = (mb_strlen($string) >= mb_strlen($hash) ? mb_strlen($hash) : mb_strlen($string));

        return substr($hash, 0, $saltPos) . $salt . substr($hash, $saltPos);
    }

    /**
     * Check string against the hash sum
     *
     * @param string $string
     * @param string $hashString
     *
     * @return bool
     */
    public static function check($string, $hashString)
    {
        $saltPos = (mb_strlen($string) >= mb_strlen($hashString) ? mb_strlen($hashString) : mb_strlen($string));
        $salt = substr($hashString, $saltPos, 12);
        $hash = hash('whirlpool', $salt . $string);

        return $hashString == substr($hash, 0, $saltPos) . $salt . substr($hash, $saltPos);
    }
}

{'fraction_non_alphanumeric': 0.15455204056991065, 'fraction_numerical': 0.009176527408838444, 'mean_word_length': 2.1715160796324655, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7609297', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1301, 'n_words': 305}