Skip to content

Instantly share code, notes, and snippets.

Last active Jul 1, 2021
What would you like to do?
Generates Minecraft-style SHA1 hashes in 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