The length of the gamma must not be less than the length of the message being protected (clear text). Otherwise, to obtain plaintext, you need to select the length of the gamma, analyze the ciphertext blocks of the correct length, and select the gamma bits.Ie, if a key with a length at least equal to the length of the message is used, the XOR cipher becomes much more robust than using the key and is repeated. If a pseudo-random number generator is used to form such a key, the result will be a stream cipher.
$encoded = bin2hex($str); $encoded = str_split($encoded, 2);
$newkey = md5($key); for($i=0;$i<1000;$i++){ $newkey = $newkey.substr(md5($newkey.$i), 6, 1); } $key = $newkey;// $binkey = ''; for($i=0;$i<(count($encoded)/16)+1;$i++){// $binkey .= md5($key.$binkey.$secret.md5($i)); } $binkey = str_split($binkey, 2);// 2
for ($i=0;$i<count($encoded);$i++){ $a = $encoded[$i]; $returnment .= bin2hex( pack('H*', $a) ^ pack('H*', $binkey[$i]) ); }
$returnment = hex2bin($returnment); $returnment = base64_encode($returnment); $returnment = str_replace('+', '-', $returnment); $returnment = str_replace('/', '_', $returnment);
$secret = md5("VIKA").md5("ONE").md5("LOVE").md5("md5('!')").md5("SECRET_PASSWAD"); $encoded = bin2hex($str); $encoded = str_split($encoded, 2); $newkey = md5($key); for($i=0;$i<1000;$i++){ $newkey = $newkey.substr(md5($newkey.$i), 6, 1); } $key = $newkey; $binkey = ''; for($i=0;$i<(count($encoded)/16)+1;$i++){ $binkey .= md5($key.$binkey.$secret.md5($i)); } $binkey = str_split($binkey, 2); $returnment = ''; for ($i=0;$i<count($encoded);$i++){ $a = $encoded[$i]; $returnment .= bin2hex( pack('H*', $a) ^ pack('H*', $binkey[$i]) ); } $returnment = hex2bin($returnment); $returnment = base64_encode($returnment); $returnment = str_replace('+', '-', $returnment); $returnment = str_replace('/', '_', $returnment); return $returnment;
$secret = md5("VIKA").md5("ONE").md5("LOVE").md5("md5('!')").md5("SECRET_PASSWAD"); $str = str_replace('-', '+', $str); $str = str_replace('_', '/', $str); $str = base64_decode($str); $str = bin2hex($str); $str = str_split($str, 2); $newkey = md5($key); for($i=0;$i<1000;$i++){ $newkey = $newkey.substr(md5($newkey.$i), 6, 1); } $key = $newkey; $binkey = ''; for($i=0;$i<(count($str)/16)+1;$i++){ $binkey .= md5($key.$binkey.$secret.md5($i)); } $binkey = str_split($binkey, 2); $returnment = ''; for ($i=0;$i<count($str);$i++){ $a = $str[$i]; $returnment .= ( pack('H*', $a) ^ pack('H*', $binkey[$i]) ); } return $returnment;
Source: https://habr.com/ru/post/279371/
All Articles