<commit_before><?php namespace System;

class Crypt {

	/**
	 * The encryption cipher.
	 *
	 * @var string
	 */
	public static $cipher = 'rijndael-256';

	/**
	 * The encryption mode.
	 *
	 * @var string
	 */
	public static $mode = 'cbc';

	/**
	 * Encrypt a value using the MCrypt library.
	 *
	 * @param  string  $value
	 * @return string
	 */
	public static function encrypt($value)
	{
		// Seed the system random number generator so it will produce random results.
		if (($random = static::randomizer()) === MCRYPT_RAND) mt_srand();

		$iv = mcrypt_create_iv(static::iv_size(), $random);

		$value = mcrypt_encrypt(static::$cipher, static::key(), $value, static::$mode, $iv);

		return base64_encode($iv.$value);
	}

	/**
	 * Decrypt a value using the MCrypt library.
	 *
	 * @param  string  $value
	 * @return string
	 */
	public static function decrypt($value)
	{
		$value = base64_decode($value, true);

		if ( ! $value)
		{
			throw new \Exception('Decryption error. Input value is not valid base64 data.');
		}

		$iv = substr($value, 0, static::iv_size());

		$value = substr($value, static::iv_size());

		return rtrim(mcrypt_decrypt(static::$cipher, static::key(), $value, static::$mode, $iv), "\0");
	}

	/**
	 * Get the random number source that should be used for the OS.
	 *
	 * @return int
	 */
	private static function randomizer()
	{
		if (defined('MCRYPT_DEV_URANDOM'))
		{
			return MCRYPT_DEV_URANDOM;
		}
		elseif (defined('MCRYPT_DEV_RANDOM'))
		{
			return MCRYPT_DEV_RANDOM;
		}
		else
		{
			return MCRYPT_RAND;
		}
	}

	/**
	 * Get the application key from the application configuration file.
	 *
	 * @return string
	 */
	private static function key()
	{
		if ( ! is_null($key = Config::get('application.key')) and $key !== '') return $key;

		throw new \Exception("The encryption class can not be used without an encryption key.");
	}

	/**
	 * Get the input vector size for the cipher and mode.
	 *
	 * Different ciphers and modes use varying lengths of input vectors.
	 *
	 * @return int
	 */
	private static function iv_size()
	{
		return mcrypt_get_iv_size(static::$cipher, static::$mode);
	}

}<commit_msg>Refactor the encryption class.<commit_after><?php namespace System;

class Crypt {

	/**
	 * The encryption cipher.
	 *
	 * @var string
	 */
	public static $cipher = 'rijndael-256';

	/**
	 * The encryption mode.
	 *
	 * @var string
	 */
	public static $mode = 'cbc';

	/**
	 * Encrypt a value using the MCrypt library.
	 *
	 * @param  string  $value
	 * @return string
	 */
	public static function encrypt($value)
	{
		// Seed the system random number generator so it will produce random results.
		if (($random = static::randomizer()) === MCRYPT_RAND) mt_srand();

		$iv = mcrypt_create_iv(static::iv_size(), $random);

		$value = mcrypt_encrypt(static::$cipher, static::key(), $value, static::$mode, $iv);

		return base64_encode($iv.$value);
	}

	/**
	 * Decrypt a value using the MCrypt library.
	 *
	 * @param  string  $value
	 * @return string
	 */
	public static function decrypt($value)
	{
		if ( ! is_string($value = base64_decode($value, true)))
		{
			throw new \Exception('Decryption error. Input value is not valid base64 data.');
		}

		$iv = substr($value, 0, static::iv_size());

		$value = substr($value, static::iv_size());

		return rtrim(mcrypt_decrypt(static::$cipher, static::key(), $value, static::$mode, $iv), "\0");
	}

	/**
	 * Get the random number source that should be used for the OS.
	 *
	 * @return int
	 */
	private static function randomizer()
	{
		if (defined('MCRYPT_DEV_URANDOM'))
		{
			return MCRYPT_DEV_URANDOM;
		}
		elseif (defined('MCRYPT_DEV_RANDOM'))
		{
			return MCRYPT_DEV_RANDOM;
		}
		else
		{
			return MCRYPT_RAND;
		}
	}

	/**
	 * Get the application key from the application configuration file.
	 *
	 * @return string
	 */
	private static function key()
	{
		if ( ! is_null($key = Config::get('application.key')) and $key !== '') return $key;

		throw new \Exception("The encryption class can not be used without an encryption key.");
	}

	/**
	 * Get the input vector size for the cipher and mode.
	 *
	 * Different ciphers and modes use varying lengths of input vectors.
	 *
	 * @return int
	 */
	private static function iv_size()
	{
		return mcrypt_get_iv_size(static::$cipher, static::$mode);
	}

}
{'fraction_non_alphanumeric': 0.1426576681405632, 'fraction_numerical': 0.005119851058878288, 'mean_word_length': 3.435500515995872, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5064622', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1379, 'n_words': 414}