import itertools, sys D='./files/universal_translator/' S=[open(D+f'samples/sample_0{i}.bin','rb').read() for i in range(1,5)] T=open(D+'transmission.bin','rb').read() EXP=[bytes.fromhex(x) for x in ['41410B2030','292A58435843','1837393923','3B3311083E1001400800 08'.replace(' ','')]] M=(1<<64)-1 STK=['DUP','DROP','SWAP','OVER','ROT','NIP','TUCK','EMIT'] ARI=['+','-','*','XOR','AND','OR','MAX','MIN','LSHIFT','RSHIFT'] class E(Exception):pass def run(prog,tab,maxout=None): s=[];out=[] for b in prog: w=tab.get(b) if w is None: s.append(b); continue if w=='DUP': if len(s)<1: raise E s.append(s[-1]) elif w=='DROP': if len(s)<1: raise E s.pop() elif w=='SWAP': if len(s)<2: raise E s[-1],s[-2]=s[-2],s[-1] elif w=='OVER': if len(s)<2: raise E s.append(s[-2]) elif w=='ROT': if len(s)<3: raise E s.append(s.pop(-3)) elif w=='NIP': if len(s)<2: raise E del s[-2] elif w=='TUCK': if len(s)<2: raise E s.insert(-2,s[-1]) elif w=='EMIT': if len(s)<1: raise E out.append(s.pop()&0xff) else: if len(s)<2: raise E b2=s.pop();a=s.pop() if w=='+':r=a+b2 elif w=='-':r=a-b2 elif w=='*':r=a*b2 elif w=='XOR':r=a^b2 elif w=='AND':r=a&b2 elif w=='OR':r=a|b2 elif w=='MAX':r=max(a,b2) elif w=='MIN':r=min(a,b2) elif w=='LSHIFT':r=a<>b2 if b2<64 else 0 s.append(r&M) return bytes(out) sols=[] for p in itertools.permutations(STK): tab=dict(zip(range(8),p)) try: if run(S[0],tab)==EXP[0] and run(S[1],tab)==EXP[1]: sols.append(tab) except E: pass print(len(sols)); [print(t) for t in sols]