Skip to content

Instantly share code, notes, and snippets.

@Ap0dexMe0
Last active June 10, 2026 18:48
Show Gist options
  • Select an option

  • Save Ap0dexMe0/0a34560fff5fcb6cc5b3f25e565054e6 to your computer and use it in GitHub Desktop.

Select an option

Save Ap0dexMe0/0a34560fff5fcb6cc5b3f25e565054e6 to your computer and use it in GitHub Desktop.
Mega888 bgluares Decryptor
#!/usr/bin/env python3
"""
Mega888 bgluares Decryptor
Decrypts XXTEA-encrypted LuaJIT bytecode files with bgluares header.
Encryption Key: cy4ty9cd
Algorithm: XXTEA
"""
import struct, sys, os
def xxtea_decrypt(data, key):
"""XXTEA decrypt bytes with key bytes."""
if len(data) < 8:
return data
n = len(data) // 4
if n < 2:
return data
data = data[:n*4]
v = list(struct.unpack(f'<{n}I', data))
k = list(struct.unpack('<4I', key[:16].ljust(16, b'\x00')))
DELTA = 0x9E3779B9
rounds = 6 + 52 // n
total = (rounds * DELTA) & 0xFFFFFFFF
y = v[0]
for _ in range(rounds):
e = (total >> 2) & 3
for p in range(n-1, 0, -1):
z = v[p-1]
mx = (((z >> 5 ^ y << 2) + (y >> 3 ^ z << 4)) ^ ((total ^ y) + (k[(p & 3) ^ e] ^ z))) & 0xFFFFFFFF
v[p] = (v[p] - mx) & 0xFFFFFFFF
y = v[p]
z = v[n-1]
mx = (((z >> 5 ^ y << 2) + (y >> 3 ^ z << 4)) ^ ((total ^ y) + (k[0 ^ e] ^ z))) & 0xFFFFFFFF
v[0] = (v[0] - mx) & 0xFFFFFFFF
y = v[0]
total = (total - DELTA) & 0xFFFFFFFF
return struct.pack(f'<{n}I', *v)
def decrypt_file(input_path, output_path=None, key=b'cy4ty9cd'):
with open(input_path, 'rb') as f:
data = f.read()
if data[:8] != b'bgluares':
raise ValueError(f"Not a bgluares file: {input_path}")
payload = data[8:]
if len(payload) % 4 != 0:
payload = payload + b'\x00' * (4 - len(payload) % 4)
decrypted = xxtea_decrypt(payload, key)
if decrypted[:3] != b'\x1bLJ':
raise ValueError(f"Decryption failed - not LuaJIT bytecode")
if output_path is None:
output_path = input_path + '.dec'
with open(output_path, 'wb') as f:
f.write(decrypted)
return output_path
if __name__ == '__main__':
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <input.luac> [output.luajit]")
sys.exit(1)
result = decrypt_file(sys.argv[1], sys.argv[2] if len(sys.argv) > 2 else None)
print(f"Decrypted: {sys.argv[1]} -> {result}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment