sofwar
11/29/2017 - 4:37 PM

Generate Hash

Generate Hash

class TestHash extends Command
{
    protected $signature = 'testhash';

    public function handle()
    {
        $user_text = 'aaaaaaaa';
        $user_steam_id = '76561198076883900';

        $public_hash = hash_hmac('sha3-512', str_random(), str_random());
        $sole = hash_hmac('sha3-512', str_random(), $public_hash);

        $private_hash = hash_hmac('sha3-512', $user_text . $user_steam_id, $sole);

        $this->info($private_hash);
        $this->info($this->getCasePercentage($private_hash));
    }

    private function getCasePercentage($hash)
    {
        $sub_hash = '';

        for ($i = 0; $i < (int)\strlen($hash); $i++) {
            $sub_hash .= $hash[$i];

            if (\strlen($sub_hash) > 7) {
                $num = hexdec($sub_hash);
                return ($num % 1000001) / 10000.0;
            }
        }

        return 0.0;
    }
}