<commit_before><?php

namespace Yab\Quarx\Services;

class CryptoService
{

    /**
     * Length of the hash to be returned
     *
     * @var interger
     */
    protected $length;

    /**
     * Encrypted Key
     * @var string
     */
    protected $encryptionKey;

    /**
     * Bad URL characters
     * @var array
     */
    protected $specialCharactersForward;

    /**
     * Bad URL characters
     * @var array
     */
    protected $specialCharactersReversed;

    /**
     * Construct the Encrypter with the fields
     *
     * @param string
     * @param string
     * @param integer
     */
    public function __construct()
    {
        $this->password = <PASSWORD>('<PASSWORD>');

        $this->specialCharactersForward = [
            '+' => '.',
            '=' => '-',
            '/' => '~'
        ];
        $this->specialCharactersReversed = [
            '.' => '+',
            '-' => '=',
            '~' => '/'
        ];
    }

    /**
     * Encrypt the string using your app and session keys,
     * then return the new encrypted string
     *
     * @param  string $value String to encrypt
     * @return string
     */
    public function encrypt($value)
    {
        $encrypted = openssl_encrypt($value, 'AES-256-CBC', $this->password, null, substr($this->password, 16));

        return $this->url_encode($encrypted);
    }

    /**
     * Decrypt a string
     *
     * @param  string $value Encrypted string
     * @return string
     *
     * @throws Exception
     */
    public function decrypt($value)
    {
        $decoded = $this->url_decode($value);

        return trim(openssl_decrypt($decoded, 'AES-256-CBC', $this->password, null, substr($this->password, 16)));
    }

    /**
     * Encode the string to be used as a url slug
     *
     * @param  string
     * @return string
     */
    protected function url_encode($string)
    {
        return rawurlencode( $this->url_base64_encode($string) );
    }

    /**
     * Decode the string to be used as a url slug
     *
     * @param  string
     * @return string
     */
    protected function url_decode($string)
    {
        return $this->url_base64_decode( rawurldecode($string) );
    }

    /**
     * Base 64 encode
     * @param  string $string String to encode<commit_msg>Improved Cryptography<commit_after><?php

namespace Yab\Quarx\Services;

class CryptoService
{

    /**
     * Length of the hash to be returned
     *
     * @var interger
     */
    protected $length;

    /**
     * Encrypted Key
     * @var string
     */
    protected $password;

    /**
     * Bad URL characters
     * @var array
     */
    protected $specialCharactersForward;

    /**
     * Bad URL characters
     * @var array
     */
    protected $specialCharactersReversed;

    /**
     * Construct the Encrypter with the fields
     *
     * @param string
     * @param string
     * @param integer
     */
    public function __construct()
    {
        $this->password = env('<PASSWORD>');

        $this->specialCharactersForward = [
            '+' => '.',
            '=' => '-',
            '/' => '~'
        ];
        $this->specialCharactersReversed = [
            '.' => '+',
            '-' => '=',
            '~' => '/'
        ];
    }

    /**
     * Encrypt the string using your app and session keys,
     * then return the new encrypted string
     *
     * @param  string $value String to encrypt
     * @return string
     */
    public function encrypt($value)
    {
        $iv = substr(md5(random_bytes(16)), 0, 16);
        $encrypted = openssl_encrypt($value, 'AES-256-CBC', $this->password, null, $iv);
        return $this->url_encode($iv.$encrypted);
    }

    /**
     * Decrypt a string
     *
     * @param  string $value Encrypted string
     * @return string
     *
     * @throws Exception
     */
    public function decrypt($value)
    {
        $decoded = $this->url_decode($value);
        $iv = substr($decoded, 0, 16);
        $encryptedValue = str_replace($iv, '', $decoded);
        return trim(openssl_decrypt($encryptedValue, 'AES-256-CBC', $this->password, null, $iv));
    }

    /**
     * Encode the string to be used as a url slug
     *
     * @param  string
     * @return string
     */
    protected function url_encode($string)
    {
        return rawurlencode( $this->url_base64_encode($string) );
    }

    /**
     * Decode the string to be used as a url slug
     *
     * @param  string
     * @return string
     */
    protected function url_decode($string)
    {
        return $this->url_base64_decode( rawurldecode($string) );
    }

    /**
     * Base 64 encode
     * @param  string $string String to encode
{'fraction_non_alphanumeric': 0.13390191897654585, 'fraction_numerical': 0.00788912579957356, 'mean_word_length': 1.8191105769230769, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 38, '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': '946792', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1389, 'n_words': 335}