#!/usr/bin/env python3

from scapy.all import *

with open("ch1", "rb") as f:
    ch1 = f.read()

with open("ch2", "rb") as f:
    ch2 = f.read()

# print(PPP(ch2[0x16a:0x186]).show())
# print(PPP(ch1[0x171:0x170+70]).show())

def decode(ch):
    buf2 = b""
    esc = False

    for x in ch:
        if x == 0x7e:
            if buf2 != b"\xFF" and buf2 != b"":
                print(PPP(buf2).__repr__())
            buf2 = b""
            esc = False
        elif esc:
            esc = False
            buf2 += bytes([x^0x20])
        elif x == 0x7d:
            esc = True
        else:
            buf2 += bytes([x])

    if len(buf2) > 0:
        print(PPP(buf2).__repr__())

print("\n", "=====================", "CH 1", "\n")
decode(ch1)
print("\n", "=====================", "CH 2", "\n")
decode(ch2)
