Rozwiązanie zadania "CRC" #24
22
main.py
Normal file
22
main.py
Normal 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:]
|
Loading…
Reference in New Issue
Block a user