function testToTransformWithUpperLowerAndNumericHexDigits() { $hash = "ff11EE22DD33CC44"; //", "0123456789AbcDef"} $hash_answer = $transform = ivcs_transform_to($hash); /* $this->assertTrue($hash_answer==$transform, "'$hash' should transform to '$hash_answer' but transformed to '$transform' instead"); print_r($transform); */ }
/////////////////////////////////////////////////// $result = ivcs_transform_from($codewords); /////////////////////////////////////////////////// $counter++; } } $time2 = time(); echo "elapsed time = ", $time2 - $time1, " seconds.<BR>"; echo "For {$counter} six-word code groups converted.<BR>"; ////////////////////////////////////////////////// //--TIMING ivcs_transform_to------------------------------------------------------ echo "<BR>"; echo "Timing ivcs_transform_to()<BR>"; //////////////////////////////////////////////////// $time1 = time(); $counter = 0; for ($i = 0; $i < $iterations; $i++) { foreach ($in as $hex) { /////////////////////////////////////////////////// $result = ivcs_transform_to($hex); /////////////////////////////////////////////////// $counter++; } } $time2 = time(); echo "elapsed time = ", $time2 - $time1, " seconds.<BR>"; echo "For {$counter} hex values converted.<BR>"; ?> </body> </html>
$time1 = time(); $result = generator(); $time2 = time(); echo "<BR>"; echo "elapsed time = ", $time2 - $time1, " seconds.<BR>"; echo "Generated ", count($result), " user OTP's<BR>"; echo "<BR>"; echo "Result of applying hash to OTP #1 (", $result[0], ")<BR>"; echo "hex version of OTP #1 = ", ivcs_transform_from(explode(" ", $result[0])), "<BR>"; //echo "hash of ",strtolower(ivcs_transform_from(explode(" ",$result[0])))," = " , __cn_hash(sha1(strtolower(ivcs_transform_from(explode(" ",$result[0]))))),"<BR>"; echo "hash of ", ivcs_transform_from(explode(" ", $result[0])), " = ", __cn_hash(sha1(ivcs_transform_from(explode(" ", $result[0])))), "<BR>"; echo "<BR>symmetry test<BR>"; echo "1st OTP from generator = ", $result[0], "<BR>"; $hex = ivcs_transform_from(explode(" ", $result[0])); echo "Hex result from ivcs_transform_from = ", $hex, "<BR>"; $six = ivcs_transform_to($hex); echo "Re-encoding result from ivcs_transform_to ", implode(" ", $six), "<BR>"; echo "<BR>"; echo "<BR>"; echo "Test of OTP table : <BR>"; $index = 1; $lastHash = __cn_hash(sha1(ivcs_transform_from(explode(" ", $result[0])))); $numfailed = 0; $numpassed = 0; foreach ($result as $sixword) { $currentHash = ivcs_transform_from(explode(" ", $sixword)); $verifyHash = __cn_hash(sha1($currentHash)); if (strcmp($verifyHash, $lastHash) == 0) { //echo "SUCCESS at ",$index, " : hash(", $sixword, ") = ",$verifyHash, ", expected ", $lastHash,"<BR>"; $numpassed++; } else {
function ivcs_transform_array_to($otpList) { if (!is_array($otpList)) { throw new Exception("passed list is not array!"); return false; } $len = count($otpList); if ($len < 1) { throw new Exception("passed list is not array!"); return false; } $sixWord = array(); for ($i = 0; $i < $len; $i++) { if (null == $otpList[$i]) { $sixWord[$i] = null; } elseif (!is_string($otpList[$i])) { $sixWord[$i] = null; } elseif (strlen($otpList[$i]) < 1) { $sixWord[$i] = null; } else { $sixWord[$i] = implode(" ", ivcs_transform_to($otpList[$i])); //////////////////// invertibilty integrity check //////////////////////////////////// $testinverse = ivcs_transform_from(explode(" ", $sixWord[$i])); if (strcmp($otpList[$i], $testinverse) != 0) { error_log("ivcs_transform_array_to : ivcs_transform not invertible"); error_log("ivcs_transform_array_to : original = " . $otpList[$i] . ", strlen = " . strlen($otpList[$i])); error_log("ivcs_transform_array_to : transform= " . $sixWord[$i]); error_log("ivcs_transform_array_to : inverted = " . $testinverse . ", strlen = " . strlen($testinverse)); } //////////////////////////////////////////////////////////////////////////////////// } } return $sixWord; }