<commit_before><?php
/**
 * Crypto
 * @package php-tool-suite
 */
require_once('var.inc.php');
require_once('random.inc.php');

if( !var_get('crypto/iv') ){
	if( extension_loaded('mcrypt') ){
		var_set('crypto/iv', $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC), MCRYPT_RAND));
	}
}

function generate_key($key) {
	return hash("SHA256", $key, true);
}

function encrypt(&$content, $key){
	if( !var_get('crypto/iv') ){
		return false;
	}
	$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $content, MCRYPT_MODE_CBC, var_get('crypto/iv'));
	$content = rtrim(base64_encode($encrypted), "\0\3");
	return (bool)$encrypted;
}

function decrypt(&$content, $key) {
	if( !var_get('crypto/iv') ){
		return false;
	}
	$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($content), MCRYPT_MODE_CBC, var_get('crypto/iv'));
	$content = rtrim($decrypted, "\0\3");
	return (bool)$decrypted;
}

?><commit_msg>ivs are now concatened to content for portability<commit_after><?php
/**
 * Crypto
 * @package php-tool-suite
 */
require_once('var.inc.php');
require_once('random.inc.php');

function generate_key($key) {
	return hash("SHA256", $key, true);
}

function encrypt(&$content, $key){
	if( !extension_loaded('mcrypt') ){
		return false;
	}
	$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC), MCRYPT_RAND);
	$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $content, MCRYPT_MODE_CBC, $iv);
	$content = $iv . rtrim(base64_encode($encrypted), "\0\3");
	return (bool)$encrypted;
}

function decrypt(&$content, $key) {
	if( !extension_loaded('mcrypt') ){
		return false;
	}
	$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
	$iv = substr($content, 0, $iv_size);
	$to_decrypt = substr($content, $iv_size);
	$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($to_decrypt), MCRYPT_MODE_CBC, $iv);
	$content = rtrim($decrypted, "\0\3");
	return (bool)$decrypted;
}

?>
{'fraction_non_alphanumeric': 0.17873417721518986, 'fraction_numerical': 0.022278481012658228, 'mean_word_length': 6.71875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2312275', 'n_tokens_mistral': 870, 'n_tokens_neox': 793, 'n_words': 127}