Last active
September 15, 2024 22:06
-
-
Save Nikdoge/474f74688b52865bf8d682a97fd4f2fe to your computer and use it in GitHub Desktop.
Generate an offline minecraft UUID v3 based on the case sensitive player name
This file contains 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
#!/usr/bin/env python3 | |
#Gets username as string, returns Minecraft offline UUID as string | |
#Translated by Nikdoge from source in PHP https://gist.github.com/games647/2b6a00a8fc21fd3b88375f03c9e2e603 | |
import hashlib | |
import sys | |
def main(): | |
#Getting argument from command line as username to convert | |
#Printing UUID | |
print(construct_offline_player_uuid(sys.argv[1])) | |
def construct_offline_player_uuid(username): | |
#extracted from the java code: | |
#new GameProfile(UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)), name)); | |
string = "OfflinePlayer:" + username | |
hash = hashlib.md5(string.encode('utf-8')).digest() | |
byte_array = [byte for byte in hash] | |
#set the version to 3 -> Name based md5 hash | |
byte_array[6] = hash[6] & 0x0f | 0x30 | |
#IETF variant | |
byte_array[8] = hash[8] & 0x3f | 0x80 | |
hash_modified = bytes(byte_array) | |
offline_player_uuid = add_uuid_stripes(hash_modified.hex()) | |
return offline_player_uuid | |
def add_uuid_stripes(string): | |
string_striped = ( | |
string[:8] + '-' + | |
string[8:12] + '-' + | |
string[12:16] + '-' + | |
string[16:20] + '-' + | |
string[20:] | |
) | |
return string_striped | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you just save my life thank you