<commit_before><?php
class UniqueKey {
	private $mode;
	private $secret;

	public function __construct($mode,$password) {
		$this->mode=$mode;
		$this->secret=$password;
	}

	private function isAES() {
		return $this->mode=="aes";
	}

	public function generate($id) {
		$obj = new stdClass;
		$obj->id = $id;
		$obj->uniqueid = mt_rand(0, 65535).uniqid();
		if($this->isAES()) {
			$cipher = MCRYPT_RIJNDAEL_256;
			$mode   = MCRYPT_MODE_ECB;
		}
		else {
			$cipher = MCRYPT_3DES;
			$mode   = MCRYPT_MODE_ECB;
		}
		return $this->do_encrypt($cipher,$mode,json_encode($obj));
	}

	public function validate($key) {
	if($this->isAES()) {
			$cipher = MCRYPT_RIJNDAEL_256;
			$mode   = MCRYPT_MODE_ECB;
		}
		else {
			$cipher = MCRYPT_3DES;
			$mode   = MCRYPT_MODE_ECB;
		}
		$json=$this->do_decrypt($cipher,$mode,$key);
		if(!($obj=json_decode($json)))
			return false;
		return $obj->id;
	}

	public function do_encrypt($cipher,$mode,$value) {
		return self::base64_url_encode(
				trim(
						mcrypt_encrypt(
								$cipher,
								$this->secret,
								$value,
								$mode,
								mcrypt_create_iv(
										mcrypt_get_iv_size(
												$cipher,
												$mode
										),
										MCRYPT_RAND
								)
						)
				)
		);
	}

	public function do_decrypt($cipher,$mode,$value) {
		return trim(
				mcrypt_decrypt(
						$cipher,
						$this->secret,
						self::base64_url_decode($value),
						$mode,
						mcrypt_create_iv(
								mcrypt_get_iv_size(
										$cipher,
										$mode
								),
								MCRYPT_RAND
						)
				)
		);
	}

	public static function base64_url_encode($input) {
		return strtr(rtrim(base64_encode($input), '='), '+/', '-_');
	}

	public static function base64_url_decode($input) {
		return base64_decode(strtr($input, '-_', '+/'));
	}
}
?><commit_msg>Add base code<commit_after><?php
require_once('EasyCrypto.php');

class UniqueKey {
	private $crypto;
	private $secret;

	public function __construct($mode,$password) {
		$this->crypto=new EasyCrypto($mode);
		$this->secret=$password;
	}

	public function generate($id, $expire=0) {
		$obj = new stdClass;
		$obj->id = $id;
		$obj->expire = $expire>0?time()+$expire:0;
		$obj->uniqueid = mt_rand(0, 65535).uniqid();
		$this->crypto->encrypt($this->secret,json_encode($obj));
	}

	public function validate($key) {
		$json=$this->crypto->decrypt($this->secret, $key);
		if(!($obj=json_decode($json)))
			return false;
		if($obj->expire>0 && time()>$obj->expire)
			return false;
		return $obj->id;
	}
}
?>
{'fraction_non_alphanumeric': 0.1695929768555467, 'fraction_numerical': 0.014365522745411013, 'mean_word_length': 3.157545605306799, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, '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': '1859817', 'n_tokens_mistral': 1246, 'n_tokens_neox': 937, 'n_words': 147}