Skip to content

Instantly share code, notes, and snippets.

@trcio
Last active August 29, 2015 14:12
Show Gist options
  • Save trcio/bf0fbe73fde2e2d56e99 to your computer and use it in GitHub Desktop.
Save trcio/bf0fbe73fde2e2d56e99 to your computer and use it in GitHub Desktop.
CREDITS GO TO MR TRVP
<?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