from binascii import unhexlify from Crypto.Cipher import AES import struct def _aschar(b): return struct.unpack("b", bytes([b & 0xFF]))[0] def _decode_kek(a): if len(a) != 16: raise ValueError("KEK incorrect length. Should be 16 was %d" % len(a)) kek = [] for b in a: c1 = _aschar(a[0] * b) c2 = _aschar((a[0] * b) // 0x5d) kek += [_aschar(c1 + c2 * -0x5d + ord('!'))] return bytes(kek) def _get_bytes(a): print(a) a = a.replace(" ", "").replace("\t", "").split(":") return unhexlify(a[0] if len(a)==1 else a[1]) kek = _decode_kek(_get_bytes(input("Enter KEK hex string line>"))) encoded_key = b"" for n in range(2): a = input("Encoded aus-key as hex string line %d>" % (n+1)) encoded_key += _get_bytes(a) cipher = AES.new(kek, AES.MODE_ECB) auskey = cipher.decrypt(encoded_key) print("Auskey:", auskey) print("Root password:", auskey[-8:])