function vizhener_encode($text,$kod) // , { $kod=strtoupper($kod); $string=strtoupper($text); $enc = array(); $dec = array(); $str="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for($i=0;$i<strlen($str);$i++) { for($j=0;$j<strlen($str);$j++) { $ij=$i+$j; if($ij>=strlen($str)) { $ij=$ij-strlen($str); } $enc[$str{$i}][$str{$j}]=$str{$ij}; $dec[$str{$i}][$str{$ij}]=$str{$j}; } } $pos=0; $result=""; $string=eregi_replace(" ","_",$string); for($i=0;$i<strlen($string);$i++) { if(!eregi($string{$i},$str)) { $result=$result.$string{$i}; } else { $result=$result.$enc[$kod{$pos}][$string{$i}]; $pos=$pos+1; if($pos>=strlen($kod)) { $pos=$pos-strlen($kod); } } } return $result; } function vizhener_encode_mod($text,$kod) // , { $kod=strtoupper($kod); $string=strtoupper($text); $enc = array(); $dec = array(); $str="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $add=mt_rand(1,9); $string=$string; for($i=1;$i<=$add;$i++) { $string=$string.$str{mt_rand(0,strlen($str))}; } for($i=0;$i<strlen($str);$i++) { for($j=0;$j<strlen($str);$j++) { $ij=$i+$j; if($ij>=strlen($str)) { $ij=$ij-strlen($str); } $enc[$str{$i}][$str{$j}]=$str{$ij}; $dec[$str{$i}][$str{$ij}]=$str{$j}; } } $pos=0; $result=""; $string=eregi_replace(" ","_",$string); $pos=$pos+$add; while($pos>=strlen($kod)) { $pos=$pos-strlen($kod); } if($pos<0) { $pos=$pos+strlen($kod); } for($i=0;$i<strlen($string);$i++) { if(!eregi($string{$i},$str)) { $result=$result.$string{$i}; } else { $result=$result.$enc[$kod{$pos}][$string{$i}]; $pos=$pos+1; if($pos>=strlen($kod)) { $pos=$pos-strlen($kod); } } } $result=$enc[$kod{0}][$add].$result; return $result; } function vizhener_decode($text,$kod) // , { $kod=strtoupper($kod); $string=strtoupper($text); $enc = array(); $dec = array(); $str="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for($i=0;$i<strlen($str);$i++) { for($j=0;$j<strlen($str);$j++) { $ij=$i+$j; if($ij>=strlen($str)) { $ij=$ij-strlen($str); } $enc[$str{$i}][$str{$j}]=$str{$ij}; $dec[$str{$i}][$str{$ij}]=$str{$j}; } } $pos=0; $result=""; $string=eregi_replace(" ","_",$string); for($i=0;$i<strlen($string);$i++) { if(!eregi($string{$i},$str)) { $result=$result.$string{$i}; } else { $result=$result.$dec[$kod{$pos}][$string{$i}]; $pos=$pos+1; if($pos>=strlen($kod)) { $pos=$pos-strlen($kod); } } } return $result; } function vizhener_decode_mod($text,$kod) // , { $kod=strtoupper($kod); $string=strtoupper($text); $enc = array(); $dec = array(); $str="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for($i=0;$i<strlen($str);$i++) { for($j=0;$j<strlen($str);$j++) { $ij=$i+$j; if($ij>=strlen($str)) { $ij=$ij-strlen($str); } $enc[$str{$i}][$str{$j}]=$str{$ij}; $dec[$str{$i}][$str{$ij}]=$str{$j}; } } $pos=0; $result=""; $string=eregi_replace(" ","_",$string); $add=$dec[$kod{0}][$string{0}]; $pos=$pos+$add; while($pos>=strlen($kod)) { $pos=$pos-strlen($kod); } if($pos<0) { $pos=$pos+strlen($kod); } for($i=1;$i<(strlen($string)-$add);$i++) { if(!eregi($string{$i},$str)) { $result=$result.$string{$i}; } else { $result=$result.$dec[$kod{$pos}][$string{$i}]; $pos=$pos+1; if($pos>=strlen($kod)) { $pos=$pos-strlen($kod); } } } return $result; }
Source: https://habr.com/ru/post/109904/
All Articles