Skip to content

Instantly share code, notes, and snippets.

@timmyrs timmyrs/mcsha1.php
Last active Oct 25, 2018

Embed
What would you like to do?
Generates Minecraft-style SHA1 hashes in PHP.
<?php
/**
* Generates a Minecraft-style SHA1 hash.
* @param string $str
* @return string
*/
function mcsha1($str)
{
$gmp = gmp_import(sha1($str, true));
if(gmp_cmp($gmp, gmp_init("0x8000000000000000000000000000000000000000")) >= 0)
{
$gmp = gmp_mul(gmp_add(gmp_xor($gmp, gmp_init("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")), gmp_init(1)), gmp_init(-1));
}
return gmp_strval($gmp, 16);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.