Last active
August 29, 2015 14:13
-
-
Save freretuc/294545336780a505cfef to your computer and use it in GitHub Desktop.
HTOP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function base32_decode($data) { | |
| $base = array_flip(array_merge(range("A","Z"), range("2", "7"))); | |
| $array = str_split(strtoupper($data)); | |
| $n = 0; | |
| $j = 0; | |
| $binary = ""; | |
| foreach($array as $c) { | |
| $n = $n << 5; | |
| $n = $n + $base[$c]; | |
| $j = $j + 5; | |
| if ($j >= 8) { | |
| $j = $j - 8; | |
| $binary .= chr(($n & (0xFF << $j)) >> $j); | |
| } | |
| } | |
| return $binary; | |
| } | |
| function GetTop($key, $counter, $length) { | |
| $cur_counter = array(0, 0, 0, 0, 0, 0, 0, 0); | |
| for($i = 7; $i >= 0; $i--) { | |
| $cur_counter[$i] = pack ('C*', $counter); | |
| $counter = $counter >> 8; | |
| } | |
| $bin_counter = implode($cur_counter); | |
| if (strlen($bin_counter) < 8) { | |
| $bin_counter = str_repeat (chr(0), 8 - strlen ($bin_counter)) . $bin_counter; | |
| } | |
| $hash = hash_hmac('sha1', $bin_counter, $key); | |
| $hmac_result = array(); | |
| foreach(str_split($hash,2) as $hex) { | |
| $hmac_result[] = hexdec($hex); | |
| } | |
| $offset = $hmac_result[19] & 0xf; | |
| $decimal = ((($hmac_result[$offset+0] & 0x7f) << 24 ) | | |
| (($hmac_result[$offset+1] & 0xff) << 16 ) | | |
| (($hmac_result[$offset+2] & 0xff) << 8 ) | | |
| ($hmac_result[$offset+3] & 0xff)); | |
| $str = str_pad($decimal, $length, "0", STR_PAD_LEFT); | |
| $str = substr($str, (-1 * $length)); | |
| return $str; | |
| } | |
| $pass = "PEHMPSDNLXIOG65U"; | |
| $seed = base32_decode($pass); | |
| var_dump(GetTop($seed, (time()/30), 6)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment