<commit_before><?php

namespace Unimatrix\Cake\Lib;

use Cake\Utility\Security;

/**
 * Paranoia
 * URL Safe encryption / decryption for integers|strings based on a secret key
 * If no key is provided it will use the security salt
 *
 * Usage example:
 * ---------------------------------
 * // controller
 * use Unimatrix\Utility\Lib\Paranoia;
 *
 * $encrypted = Paranoia::encrypt('string_to_encrypt');
 * $decrypted = Paranoia::decrypt('string_to_decrypt');
 *
 * @author Flavius
 * @version 1.0
 */
class Paranoia
{
    /**
     * Get secret key from either
     * the security salt or from parameter
     *
     * @param string $s
     * @return string
     */
    private static function secret($s = null) {
        return is_null($s) ? Security::getSalt() : $s;
    }

    /**
     * Encrypt
     *
     * @param integer|string $a
     * @param string $s Paranoia secret
     * @return null|string
     */
    public static function encrypt($a = null, $s = null) {
        if(is_null($a))
            return $a;

        $b = Security::encrypt($a, md5(self::secret($s)));
        return strtr(base64_encode($b), '+/=', '-_.');
    }

    /**
     * Decrypt
     *
     * @param string $a
     * @param string $s Paranoia secret
     * @return null|integer|string
     */
    public static function decrypt($a = null, $s = null) {
        if(is_null($a))
            return $a;

        $b = base64_decode(strtr($a, '-_.', '+/='));
        return Security::decrypt($b, md5(self::secret($s)));
    }
}<commit_msg>Paranoia 1.1<commit_after><?php

namespace Unimatrix\Cake\Lib;

use Cake\Utility\Security;

/**
 * Paranoia
 * URL Safe encryption / decryption for integers|strings based on a secret key
 * If no key is provided it will use the security salt
 *
 * Usage example:
 * ---------------------------------
 * // controller
 * use Unimatrix\Utility\Lib\Paranoia;
 *
 * $encrypted = Paranoia::encrypt('string_to_encrypt');
 * $decrypted = Paranoia::decrypt('string_to_decrypt');
 *
 * @author Flavius
 * @version 1.1
 */
class Paranoia
{
    /**
     * Get secret key from either
     * the security salt or from parameter
     *
     * @param string $secret
     * @return string
     */
    private static function secret($secret = null) {
        return is_null($secret) ? Security::getSalt() : $secret;
    }

    /**
     * Encrypt
     * @param integer|string $input
     * @param string $secret Paranoia secret
     * @return boolean|string
     */
    public static function encrypt($input, $secret = null) {
        // no input?
        if(!$input)
            return false;

        // encrypt
        $encrypted = Security::encrypt($input, md5(self::secret($secret)));

        // encode
        return strtr(base64_encode($encrypted), '+/', '-_');
    }

    /**
     * Decrypt
     * @param string $input
     * @param string $secret Paranoia secret
     * @return boolean|string|boolean
     */
    public static function decrypt($input, $secret = null) {
        // no input?
        if(!$input)
            return false;

        // backwards 1.0 compatibility
        $input = strtr($input, '.', '=');

        // decode
        $decoded = base64_decode(str_pad(strtr($input, '-_', '+/'), strlen($input) % 4, '=', STR_PAD_RIGHT));
        if(!$decoded)
            return false;

        // decrypt
        return Security::decrypt($decoded, md5(self::secret($secret)));
    }
}
{'fraction_non_alphanumeric': 0.1618683901292597, 'fraction_numerical': 0.006169212690951821, 'mean_word_length': 2.227488151658768, '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': '5483817', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1046, 'n_words': 258}