Last active
August 29, 2015 14:12
-
-
Save trcio/bf0fbe73fde2e2d56e99 to your computer and use it in GitHub Desktop.
CREDITS GO TO MR TRVP
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 | |
class MbamGen { | |
public function get_key() { | |
$data = [ | |
'id' => $this->random_char() . $this->random_char() . $this->random_char() . $this->random_char() . $this->random_char(), | |
'key' => '' | |
]; | |
$hash = strtoupper(md5($data['id'])); | |
for ($i = 0; $i < 32; $i += 2) { | |
$nextDigit = hexdec(substr($hash, $i, 2)) & 31; | |
$withDash = ((($i % 8) == 0) && ($i > 0)); | |
$data['key'] .= ($withDash ? '-' : ''); | |
$data['key'] .= substr($this->get_chars(), $nextDigit, 1); | |
} | |
return $data; | |
} | |
private function random_char() { | |
return $this->get_chars()[mt_rand(10, strlen($this->get_chars()) - 1)]; | |
} | |
private function get_chars() { | |
return '0123456789ABCDEFGHJKLMNPQRTUVWXY'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment