Last active
November 1, 2024 18:37
-
-
Save timmyRS/e1922033029e9171c00b21c4a19c7c81 to your computer and use it in GitHub Desktop.
Generates Minecraft-style SHA1 hashes in PHP.
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 | |
/** | |
* 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