#!/usr/bin/env python3

import pathlib

mapping = {}

for file in pathlib.Path("src").iterdir():
    if "Main" in file.name:
        continue
    name = file.name.replace(".java", "")
    with file.open("r") as f:
        data = f.read()
    thisfile = {}
    mname = None
    for line in data.split("\n"):
        if mname is None:
            if "public String" in line:
                mname = line.strip().split(" ")[2].replace("()", "")
        else:
            val = line.strip().split(" ")[1].replace('"', "").replace(";", "")
            thisfile[mname] = val
            mname = None
    mapping[name] = thisfile

import pprint
pprint.pprint(mapping)

start = "javautil"

def rfind(what):
    for file,data in mapping.items():
        for k,v in data.items():
            if v == what and k in data.values():
                for k2, v2 in data.items():
                    if v2 == k and k2 in data.values():
                        for k3, v3 in data.items():
                            if v3 == k2:
                                return file + k3

data = rfind("ja") + rfind("va") + rfind("ut") + rfind("il")

data = bytearray(data.encode())
for i in range(len(data)):
    data[i] ^= 2

print(data)
