Skip to content

Instantly share code, notes, and snippets.

@adamjasinski
Created February 12, 2022 17:34
Show Gist options
  • Save adamjasinski/26c5a674f662d7c10e9748e3278087a9 to your computer and use it in GitHub Desktop.
Save adamjasinski/26c5a674f662d7c10e9748e3278087a9 to your computer and use it in GitHub Desktop.
Decodes a Base32 command-line parameter to UUID, using .NET Guid-compatible byte order
#!/usr/bin/python3
import uuid
import base64
import sys
def base32decode(s):
# NB - input should be a hex string of 26 characters
padded_bytes = f"{s}======".encode('ascii')
decoded_bytes = base64.b32decode(padded_bytes, casefold=True)
# NB - bytes_le uses .NET Guid-compatible byte order
guid = uuid.UUID(bytes_le=decoded_bytes)
return guid
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} base32-encoded-uuid")
exit(1)
guid = base32decode(sys.argv[1])
print(guid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment