if ($Result === $Key) { echo 'PASS'; } else { echo "FAIL ('" . $Key . "')"; } echo "\n"; } echo "\nBase32 Encode/Decode Excercise"; $Passes = 100; $MaxLen = 100; $Failures = 0; mt_srand(); for ($i = 0; $i < $Passes; $i++) { $RandStr = ''; $Len = mt_rand(0, $MaxLen); for ($Leni = 0; $Leni < $Len; $Leni++) { $RandStr .= chr(mt_rand(0, 255)); } $Encoded = Base32::Encode($RandStr); $Decoded = Base32::Decode($Encoded); if ($Decoded != $RandStr) { echo "\nFAIL\n"; echo "Input:\t\t " . DumpBinStr($RandStr) . "\n"; echo "Encoded:\t " . $Encoded . "\n"; echo "Decoded:\t " . DumpBinStr($Decoded) . "\n"; $Failures++; } } if ($Failures == 0) { echo ": PASS\n"; }
#!/usr/bin/php -q <?php require_once 'PHPOTP.php'; require_once 'Base32.php'; $OTP = new PHPOTP(); $Secret = $OTP->GenSeed(); $Base32Secret = Base32::Encode($Secret); echo 'Secret (Base32): ' . $Base32Secret . "\n"; echo 'HOTP: ' . $OTP->HOTP($Secret) . "\n"; echo 'TOTP: ' . $OTP->TOTP($Secret) . "\n"; echo $OTP->HOTPAsURI('The Issuer', 'A Label', $Base32Secret, 0) . "\n"; echo $OTP->TOTPAsURI('The Issuer', 'A Label', $Base32Secret) . "\n";