Skip to content

maycon/uuid-decoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

UUID Decoder - RFC 9562

Complete UUID decoder for versions 1-8 as specified in RFC 9562.

πŸ“‹ Features

  • βœ… Full support for UUIDv1 through UUIDv8
  • βœ… Extraction of all fields as defined in RFC 9562
  • βœ… Timestamp conversion to readable format
  • βœ… Reconstruction of fragmented timestamps
  • βœ… Multiple output formats (human-readable, JSON, CSV)
  • βœ… Simple mode for streamlined output
  • βœ… Detailed documentation for each field

πŸš€ Quick Start

# Human-readable output (default)
python uuid_decoder.py 6ba7b810-9dad-11d1-80b4-00c04fd430c8

# JSON output
python uuid_decoder.py --json 018e8f54-9b85-7a3a-a123-456789abcdef

# Simple JSON (flat structure, no descriptions)
python uuid_decoder.py --simple --json uuid1 uuid2

# CSV output
python uuid_decoder.py --csv uuid1 uuid2 uuid3 > output.csv

πŸ“– Command-Line Options

Basic Usage

python uuid_decoder.py [OPTIONS] <uuid1> [uuid2] [uuid3] ...

Options

Option Description
--json Output as JSON format (pipeable to jq)
--simple Simplified output without descriptions or nested objects
--csv Output as CSV format
-h, --help Show help message

Option Combinations

  • Default (no options): Human-readable output with all details
  • --json: Full JSON with nested structure and descriptions
  • --simple --json: Flat JSON structure, essential fields only
  • --csv: Flattened CSV format for spreadsheet import

πŸ“Š Output Format Examples

1. Human-Readable (Default)

python uuid_decoder.py 018e8f54-9b85-7a3a-a123-456789abcdef

Output:

UUID: 018e8f54-9b85-7a3a-a123-456789abcdef
Version: 7
Variant: RFC 4122/9562
Type: Unix Epoch time-based UUID

--------------------------------------------------------------------------------
DECODED FIELDS:
--------------------------------------------------------------------------------

unix_ts_ms:
  value: 1711801670533
  hex: 0x018e8f549b85
  bits: 0-47
  unix_timestamp: 1711801670.533
  datetime_utc: 2024-03-30T12:27:50.533000+00:00
  datetime_readable: 2024-03-30 12:27:50.533000 UTC
  β†’ Unix timestamp in milliseconds

Entropy bits: 74

2. JSON Output

python uuid_decoder.py --json 018e8f54-9b85-7a3a-a123-456789abcdef

Output:

[
  {
    "uuid": "018e8f54-9b85-7a3a-a123-456789abcdef",
    "version": 7,
    "variant": "RFC 4122/9562",
    "type": "Unix Epoch time-based UUID",
    "fields": {
      "unix_ts_ms": {
        "value": 1711801670533,
        "hex": "0x018e8f549b85",
        "bits": "0-47",
        "unix_timestamp": 1711801670.533,
        "datetime_utc": "2024-03-30T12:27:50.533000+00:00",
        "datetime_readable": "2024-03-30 12:27:50.533000 UTC",
        "description": "Unix timestamp in milliseconds"
      }
    },
    "entropy_bits": 74
  }
]

3. Simple JSON Output

python uuid_decoder.py --simple --json 018e8f54-9b85-7a3a-a123-456789abcdef

Output:

[
  {
    "uuid": "018e8f54-9b85-7a3a-a123-456789abcdef",
    "version": 7,
    "variant": "RFC 4122/9562",
    "unix_ts_ms": 1711801670533,
    "timestamp_unix": 1711801670.533,
    "datetime_utc": "2024-03-30T12:27:50.533000+00:00",
    "datetime_readable": "2024-03-30 12:27:50.533000 UTC",
    "rand_a": 2618,
    "rand_b": 2387828538430180847,
    "entropy_bits": 74
  }
]

Perfect for processing with jq:

python uuid_decoder.py --simple --json uuid1 uuid2 | jq '.[].datetime_readable'

4. CSV Output

python uuid_decoder.py --csv uuid1 uuid2 uuid3 > output.csv

Can be imported directly into Excel, Google Sheets, or any CSV-compatible tool.

πŸ“‹ Supported UUID Versions

UUIDv1 - Time-based (Gregorian Epoch)

Based on timestamp since October 15, 1582, and MAC address.

Fields:

  • time_low, time_mid, time_hi: Timestamp components
  • clock_seq: Clock sequence (14 bits)
  • node: MAC address (48 bits)
  • Reconstructed: datetime_utc, timestamp_unix

UUIDv2 - DCE Security

Similar to v1 with local domain and ID fields.

Fields:

  • local_domain: POSIX UID, GID, or ORG
  • local_id: Local identifier
  • Timestamp and node fields

UUIDv3 - Name-based (MD5)

Deterministic UUID from MD5(namespace + name).

Fields:

  • hash_md5: MD5 hash value

UUIDv4 - Random

Completely random with 122 bits of entropy.

Fields:

  • random_a, random_b, random_c, random_d: Random components
  • entropy_bits: 122

UUIDv5 - Name-based (SHA-1)

Deterministic UUID from SHA-1(namespace + name).

Fields:

  • hash_sha1: SHA-1 hash value
  • More secure than v3

UUIDv6 - Reordered Time-based

Reordered v1 for lexicographic sorting.

Fields:

  • time_high, time_mid, time_low: Reordered timestamp
  • clock_seq, node: Same as v1
  • Advantage: Natural time-based sorting

UUIDv7 - Unix Timestamp-based

Modern time-based UUID with Unix timestamp.

Fields:

  • unix_ts_ms: Unix timestamp in milliseconds
  • rand_a, rand_b: Random components (74 bits total)
  • Recommended for new projects

UUIDv8 - Custom/Experimental

Customizable format for application-specific needs.

Fields:

  • custom_a, custom_b, custom_c, custom_d: Customizable (122 bits)

🎯 Use Cases

1. Debugging

# Check UUID version and timestamp
python uuid_decoder.py <uuid>

2. Data Analysis

# Export multiple UUIDs to CSV for analysis
python uuid_decoder.py --csv uuid1 uuid2 uuid3 > analysis.csv

3. API Integration

# Parse UUID info in scripts
UUID_INFO=$(python uuid_decoder.py --simple --json $UUID)
VERSION=$(echo $UUID_INFO | jq '.[0].version')

4. Timestamp Extraction

# Get creation timestamp from UUIDv1 or UUIDv7
python uuid_decoder.py --simple --json $UUID | jq '.[0].datetime_readable'

πŸ”§ Integration Examples

Bash Script

#!/bin/bash
# Process UUIDs from file
while IFS= read -r uuid; do
    python uuid_decoder.py --simple --json "$uuid"
done < uuids.txt

Python Script

#!/usr/bin/env python3
from uuid_decoder import UUIDDecoder

# Decode UUID
decoder = UUIDDecoder("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
result = decoder.decode(simple=True)

print(f"Version: {result['version']}")
print(f"Timestamp: {result['datetime_readable']}")

JSON Processing

# Extract all timestamps
python uuid_decoder.py --simple --json *.uuid | \
  jq -r '.[] | select(.datetime_utc) | .datetime_utc'

# Filter by version
python uuid_decoder.py --simple --json *.uuid | \
  jq '.[] | select(.version == 7)'

πŸ“š Documentation

πŸ§ͺ Testing

# Generate examples
python examples.py

# Test decoder
python uuid_decoder.py --json $(python -c "import uuid; print(uuid.uuid1())")

πŸ“„ RFC 9562 Compliance

This decoder is 100% compliant with RFC 9562:

  • βœ… All 8 UUID versions supported
  • βœ… Exact field names from specification
  • βœ… Correct bit-level extraction
  • βœ… Proper timestamp reconstruction
  • βœ… Accurate epoch handling (Gregorian/Unix)

πŸš€ Performance

  • Fast: Pure Python, no external dependencies
  • Memory efficient: Processes UUIDs one at a time
  • Batch processing: Handle multiple UUIDs in one command

πŸ”’ Requirements

  • Python 3.6+
  • No external dependencies (uses only standard library)

πŸ“– References

πŸ“ License

Public domain - use freely for any purpose.


Made with ❀️ for the UUID community

About

Decodes UUIDs versions 1-8 showing all fields as specified in RFC 9562

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages