#!/usr/bin/env python3 import sys def main(): if len(sys.argv) < 2: print("Benutzung: 13 Byte bzw. 26bit Hex ffff0123456789abcdef012345 ".format(sys.argv[0])) sys.exit(1) byte_array = bytearray.fromhex(sys.argv[1]) #from RADIO HACKER if len(byte_array)!=13: print(byte_array) print("Falsche Länge ! {}".format(byte_array)) sys.exit(1) checksum=0 for i in range(2,12): checksum=checksum^byte_array[i] if checksum==byte_array[12]: print("Checksumme ok") else: print(checksum) print(f"Falsche Checksumme, sollte sein {checksum:02X} aber ist {byte_array[12]:02X}") ide = int.from_bytes(byte_array[2:6], byteorder='big') print(f"ide {ide:08X}") button=(byte_array[6]>>4)&0x3 print(f"button {button:01X}") counter=byte_array[6]&0xF counter=counter<<6 counter+=byte_array[7]>>2 #the two lsb are the two msb of the secret/crypt print(f"counter {counter:03X}") secret = int.from_bytes(byte_array[8:12], byteorder='big') secret=secret>>2 secret+=(byte_array[7]&0x3)<<30 #the two bits after the counter are the high bits of the secret/crypt print(f"secret {secret:08X}") #this is needed for the next CTF print("\ndata for htcrack:") print(f"UID {ide:08X}") #IV is in this case just the counter plus 4bits with the button value iv=(counter<<4)+button print(f"nRx {iv:08X}") print(f"aRx {secret^0xFFFFFFFF:08X}") if __name__ == "__main__": try: main() except KeyboardInterrupt: print("Abbruch durch Benutzer") finally: print("Bye bye")