private static function runKakunaTest() { /** * @var Kakuna; */ $kakunaAlgo = Hasher::createAlgorithm('kakuna', 3); $i = 0; $failedCount = 0; $successCount = 0; echo "\n\tStart testing for algo \"KAKUNA\"\n"; foreach (self::$kakunaTestWords as $word) { echo "\n====================Test #" . ++$i . "====================\n"; echo "\tInput word: " . $word . "\n"; $resultWord = $kakunaAlgo->decode($kakunaAlgo->encode($word)); echo "\tInput word after algo encode-decode: " . $resultWord . "\n"; if ($word !== $resultWord) { echo "!!!!!!!!!!!!!!!ERROR!!!!!!!!!!!!!!!!!\n"; echo "Word is: " . $word . "\n"; echo "Encoded-Decode word is: " . $resultWord . "\n"; echo "\tTest #" . $i . " failed\n\n"; $failedCount++; } else { echo "\tTest #" . $i . " completed\n\n"; $successCount++; } } echo "\tEnd testing for algo \"KAKUNA\", Total count: {$i}; Success count: {$successCount}; Failed count: {$failedCount}\n\n"; }
} $chosenMethod = read_stdin(); $methodName = $methods[$chosenMethod - 1]; echo "Ok! You've choose algorithm \"" . $algorithmName . "\" and method \"" . $methodName . "\"\n"; if (!is_null($algorithmMap[$algorithmName]['construct_parameters'])) { echo "Algorithm you've choose needs some constructor parameters: \n"; foreach ($algorithmMap[$algorithmName]['construct_parameters']['parameters'] as $parameterType => $parameterName) { echo "\tPlease enter " . $parameterType . " value. It'll be a " . $parameterName . " for " . $algorithmName . " algorithm:\n"; } $constructParameters = read_stdin(); echo "\n"; echo "Ok! Parameter is: " . $constructParameters; echo "\n\n"; } echo "\n"; echo "Now, enter word you want to " . $methodName . ": \n"; $wordToHash = read_stdin(); $wordToHash = trim($wordToHash); /** * @var \Library\Algorithm\Kakuna|\Library\Algorithm\Seqswap */ try { $result = Hasher::createAlgorithm($algorithmName, $constructParameters)->{$methodName}($wordToHash); } catch (Exception $e) { echo "Error: " . $e->getMessage() . "\n"; return; } echo "Wow! We've done! Here is result: \n"; echo $result; echo "\n\n"; }