Created
August 7, 2018 11:30
-
-
Save chekalsky/d9e0453721454ef5dc7bc7e9ad1f1882 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$vars = []; | |
$hashes = []; | |
do { | |
$variant_first_row = []; | |
$variant_second_row = []; | |
$max = 5; | |
for ($i = 0; $i <= $max; $i++) { | |
$variant_first_row[$i] = $i; | |
if ($i === 3) { | |
$max_l = 179; | |
$min_l = 1; | |
} else { | |
$max_l = 59; | |
$min_l = 0; | |
} | |
$value = random_int($min_l, $max_l); | |
$variant_second_row[$i] = $value; | |
} | |
do { | |
shuffle($variant_first_row); | |
foreach ($variant_first_row as $i => $item) { | |
if ($i === $item) { | |
continue 2; | |
} | |
if ($item === 0 && $i !== $max) { | |
continue 2; | |
} | |
} | |
break; | |
} while (true); | |
$result = []; | |
$i = 0; | |
for ($k = 0; $k <= $max; $k++) { | |
$i = $variant_first_row[$i]; | |
$result[$i] = $variant_second_row[$k]; | |
} | |
if (\count($result) !== $max + 1) { | |
continue; | |
} | |
ksort($result); | |
$r = [ | |
$variant_first_row, | |
$result | |
]; | |
$hash = md5(serialize($r)); | |
if (isset($hashes[$hash])) { | |
continue; | |
} | |
$hashes[$hash] = true; | |
$vars[] = $r; | |
} while (count($vars) < 250); | |
function str_split_unicode($str, $l = 0) | |
{ | |
if ($l > 0) { | |
$ret = array(); | |
$len = mb_strlen($str, "UTF-8"); | |
for ($i = 0; $i < $len; $i += $l) { | |
$ret[] = mb_substr($str, $i, $l, "UTF-8"); | |
} | |
return $ret; | |
} | |
return preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY); | |
} | |
function sdvig($text, $move_to = 4) | |
{ | |
$alphabet = ['а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я']; | |
$alphabet = array_reverse($alphabet); | |
$new_alphabet = $alphabet; | |
$new_alphabet_part = array_splice($new_alphabet, $move_to); | |
$new_alphabet = array_merge($new_alphabet_part, $new_alphabet); | |
$alphabet = array_flip($alphabet); | |
$text_array = str_split_unicode($text); | |
$result_text = ''; | |
foreach ($text_array as $item) { | |
if (isset($alphabet[$item])) { | |
$letter = $new_alphabet[$alphabet[$item]]; | |
} elseif (isset($alphabet[mb_strtolower($item)])) { | |
$letter = mb_strtoupper($new_alphabet[$alphabet[mb_strtolower($item)]]); | |
} else { | |
$letter = $item; | |
} | |
$result_text .= $letter; | |
} | |
return $result_text; | |
} | |
$bad = $good = 0; | |
foreach ($vars as $zz => $var) { | |
$arr1 = $var[1]; | |
$arr2 = $var[0]; | |
$res = []; | |
$i = 0; | |
$imax = count($arr2); | |
for ($k = 0; $k < $imax; $k++) { | |
$i = $arr2[$i]; | |
$res[] = $arr1[$i]; | |
} | |
$text = ['Ave, друг. Надеюсь, ты достаточно умён, чтобы найти координаты.' , 'Вот твои входные данные, только поменяй их местами:']; | |
$sdvig = ($zz+1)%32; | |
$sdvig = $sdvig === 0 ? 32 : $sdvig; | |
echo $zz+1 . ';'; | |
echo sdvig($text[0], $sdvig); | |
echo ';'; | |
echo sdvig($text[1], $sdvig); | |
echo ';'; | |
echo implode(',', $arr2); | |
echo ' '; | |
echo implode(',', $arr1); | |
echo "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment