Rozwiązanie zadania "CRC" #24

Closed
s426211 wants to merge 8 commits from (deleted):zad3 into master
Showing only changes of commit 7fb10a9d28 - Show all commits

22
main.py Normal file
View File

@ -0,0 +1,22 @@
if __name__ == "__main__":
message = format(int.from_bytes(input().encode("ASCII"), "big"), "b")
generator = "10001000000100001"
gen_deg = len(generator)
message += "0" * (gen_deg - 1)
if len(message) % 2 != 0:
message = "0" + message
while True:
if message[0] == "0":
message = message[1:]
else:
chunk = message[:gen_deg]
if len(chunk) < gen_deg:
print(hex(int(chunk, 2)))
break
remainder = format(int(chunk, 2) ^ int(generator, 2), "b")
message = remainder + message[gen_deg:]