INNER CODE UNIT · Python

hex_to_bytes

KnifeXRage/Godot-Secure · Godot Secure Scripts/universal/Godot Secure AES-256 Universal v6.py:37

def hex_to_bytes(hex_string: str) -> bytes:
    return bytes.fromhex(hex_string)

def generate_magic_header(tag: str, endian='little') -> str:
    if len(tag) != 4:
        raise ValueError("Tag must be exactly 4 characters.")
    
    if endian == 'little':
        tag = tag[::-1]  # Reverse for little-endian

    hex_value = "0x" + ''.join(f"{ord(c):02X}" for c in tag)
    return hex_value

def generate_random_gdtokenizer_seed(length: int = 64) -> str:
    
    # secrets.token_hex(n) returns a string of 2 * n hex characters
    return secrets.token_hex(length // 2)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…