#!/usr/bin/env python3
# XOR Decryption Script for APK Strings
# Key found in NPStringFog.smali: "400017**%%$shadeed"

def hex_to_bytes(hex_string):
    """Convert hex string to bytes"""
    result = bytearray()
    for i in range(0, len(hex_string), 2):
        byte_val = int(hex_string[i:i+2], 16)
        result.append(byte_val)
    return bytes(result)

def xor_decrypt(encrypted_hex, key):
    """Decrypt XOR encrypted hex string with given key"""
    try:
        # Convert hex to bytes
        encrypted_bytes = hex_to_bytes(encrypted_hex)

        # XOR decrypt
        decrypted = bytearray()
        key_len = len(key)

        for i, byte in enumerate(encrypted_bytes):
            key_char = ord(key[i % key_len])
            decrypted_byte = byte ^ key_char
            decrypted.append(decrypted_byte)

        # Convert to string
        return decrypted.decode('utf-8', errors='ignore')
    except Exception as e:
        return f"Error: {e}"

# Key from NPStringFog.smali line 17
KEY = "400017**%%$shadeed"

# Encrypted strings found in the APK
encrypted_strings = [
    "55535355424443484C494D0711",
    "62595547115A4B53054B4B07480301450B11585C",
    "50594255524343454B0549061B15440700445B5E55105E510A51636A67263B3E31354944727F736562686E65726B08532E2E2730363B787576641D176C656670772C3A28232D31191A",
    "50594255524343454B0549061B15440700445B5E55105E510A51636A67263B3E222A37337562741C1171656970767B3129222F322436701C10767E747F797A70745F48272B2630376B747F677F1B0A6C6A667120372D2123314814767F73646475786C626C27154F",
    "77515C5C53564941560549061B1544040100144455484517455805440410070F10000B10145455435245435A514C4B1D48080A45150B44455C5145526F5C404B50350713320C171041515C6658525D63410D0D",
    "555E54425E5E4E04534C410446370D0012",
    "77515C5C53564941560549061B1544040100144455484517455805440410070F10000B10145455435245435A514C4B1D48080A45150B44455C51455264454140621C1A370D171111555C66595440634E0D0C",
    "77515C5C53564941560549061B15440B0A10145154541176697E6C6A6A2C2B2D2124373B75737375626463686C696D27313E222A26316710595E1147455A504945070D2F0B0100225B42665943435F4B49734D161F28004D4C",
    "77515C5C53564941560549061B15440B0A10145154541176697E6C6A6A2C2922272036377D72797C78637375636A67263B410D0B45145B40455C50434F644A4141350713320C171041515C6658525D63410D0D",
    "77515C5C53564941560549061B15441600101440514254595E0A474A511D0C12440C0B44445F40455D565E4F6B4A40162E0E16330C164045515C675E4F5D6C410C5A",
    "625955474217494B4B4B4B07480905130044565F445811454F4B4905451D0C41120C171041515C10525F43464157411D",
]

print("=" * 80)
print("XOR Decryption Results")
print("=" * 80)
print(f"Key: {KEY}")
print("=" * 80)

for i, enc_str in enumerate(encrypted_strings, 1):
    decrypted = xor_decrypt(enc_str, KEY)
    print(f"\n[{i}] Encrypted: {enc_str[:50]}{'...' if len(enc_str) > 50 else ''}")
    print(f"    Decrypted: {decrypted}")

print("\n" + "=" * 80)
