Vad gör följand två rader?
Kod: Markera allt
$encoded .= ModHex::$TRANSKEY[((int)$bin >> 4) & 0xf];
$encoded .= ModHex::$TRANSKEY[ (int)$bin & 0xf];
Kod: Markera allt
/*
yubikey.php
Written by John E. Woltman IV
Released under the LGPL v2.
Based on code from Yubico's C and Java server samples.
WARNING: I have not tested this with an actual yubikey yet, only with
the sample output included in yubico-c's README file.
NOTICE: This class DOES NOT track or log a Yubikey's counters and
timestamps. You can use this code to integrate Yubikey authentication
into your own backend authentication system and keep track of the necessary
information yourself.
Please see the file yubitest.php for a test scenario.
*/
class ModHex {
static $TRANSKEY = "cbdefghijklnrtuv"; // translation key used to ModHex a string
// ModHex encodes the string $src
static function encode($src) {
$encoded = "";
$i = 0;
$srcLen = strlen($src);
for ($i = 0; $i < $srcLen; $i++) {
$bin = (ord($src[$i]));
$encoded .= ModHex::$TRANSKEY[((int)$bin >> 4) & 0xf];
$encoded .= ModHex::$TRANSKEY[ (int)$bin & 0xf];
}
return $encoded;
}
// ModHex decodes the string $token. Returns the decoded string if successful,
// or zero if an encoding error was found.
static function decode($token) {
$tokLen = strlen($token); // length of the token
$decoded = ""; // decoded string to be returned
// strings must have an even length
if ( $tokLen % 2 != 0 ) { return FALSE; }
for ($i = 0; $i < $tokLen; $i=$i+2 ) {
$high = strpos(ModHex::$TRANSKEY, $token[$i]);
$low = strpos(ModHex::$TRANSKEY, $token[$i+1]);
// if there's an invalid character in the encoded $token, fail here.
if ( $high === FALSE || $low === FALSE )
return FALSE;
$decoded .= chr(($high << 4) | $low);
}
return $decoded;
}