21 $cur_counter =
array( 0, 0, 0, 0, 0, 0, 0, 0 );
22 for ( $i = 7; $i >= 0; $i-- ) {
23 $cur_counter[$i] = pack(
'C*', $counter );
24 $counter = $counter >> 8;
27 $bin_counter = implode( $cur_counter );
30 if ( strlen( $bin_counter ) < 8 ) {
31 $bin_counter = str_repeat(
"\0", 8 - strlen( $bin_counter ) ) . $bin_counter;
35 $hash = hash_hmac(
'sha1', $bin_counter, $key );
50 if ( !$timestamp && $timestamp !== 0 ) {
54 $counter = (int)( $timestamp / $window );
73 $max = 1, $timestamp =
false
75 if ( !$timestamp && $timestamp !== 0 ) {
79 $counter = (int)( $timestamp / $window );
80 $window = range( $min, $max );
83 $length =
count( $window );
84 for ( $i = 0; $i < $length; $i++ ) {
85 $shift_counter = $counter + $window[$i];
123 $hmac_result =
array();
126 foreach ( str_split( $this->hash, 2 )
as $hex ) {
127 $hmac_result[] = hexdec(
$hex);
130 $offset = $hmac_result[19] & 0xf;
133 ( ( $hmac_result[$offset+0] & 0x7f ) << 24 ) |
134 ( ( $hmac_result[$offset+1] & 0xff ) << 16 ) |
135 ( ( $hmac_result[$offset+2] & 0xff ) << 8 ) |
136 ( $hmac_result[$offset+3] & 0xff )
140 $this->hex = dechex( $this->decimal );
173 $str = str_pad( $this->
toDec(), $length,
"0", STR_PAD_LEFT );
174 $str = substr( $str, ( -1 * $length ) );