Skip to content

Instantly share code, notes, and snippets.

@Nikdoge
Last active September 15, 2024 22:06
Show Gist options
  • Save Nikdoge/474f74688b52865bf8d682a97fd4f2fe to your computer and use it in GitHub Desktop.
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
#!/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()
@david-benistant
Copy link

you just save my life thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment