Affine

Words
0
Reading
0 min
Listen
Play
2y
<?php . \* \* To disable strict typing, comment out the directive below. \*/ declare(strict\_types=1); function encode(string $text, int $num1, int $num2): string{ $res = ""; $alphabet = range('a', 'z'); $lowerString = strtolower($text); $counter = 0; if(!isGcd($num1, 26)){throw new Exception();} foreach (str\_split($lowerString) as $char){ if(in\_array($char, $alphabet)){ $index = array\_search($char, $alphabet); $enc = ($num1 \* ($index) + $num2) % 26; $enc = ($enc +26) % 26; $res.= $alphabet[$enc]; } else if (ctype\_digit($char)){ $res.= $char;} else{continue;} $counter++; if($counter === 5){ $res.= ' '; $counter = 0;} } return trim($res); } function isGcd($a, $m){ while($m != 0){ $temp = $m; $m = $a % $m; $a = $temp; } return $a===1; } function mmi($a){ $m =26; for($i=0; $i
Affine | Ecency