diff --git a/Zadanie3 b/Zadanie3 index bcc7acd..6186275 100644 --- a/Zadanie3 +++ b/Zadanie3 @@ -1,6 +1,7 @@ from sys import argv import sys import binascii +import base64 def toBinary(string): return "".join([format(ord(char),'#010b')[2:] for char in string]) @@ -101,7 +102,8 @@ def decode(message,poly16,crc): obroc[i] = "0" msg = "".join(obroc) - + print(msg) + print(crc2) remainder = divide(msg, poly16) #Poprawione sprawdzanie suma = 0 @@ -114,6 +116,36 @@ def decode(message,poly16,crc): elif suma > 0: print("false") +def decode(message,poly16,crc): + l_poly16 = len(poly16) + message = bytearray(message, 'ascii') + message = format(int.from_bytes(message, "big"), "b") + dec = int(crc, 16) + crc2=bin(dec)[2:] + msg=message+crc2 + while len(msg) % 8 != 0: + msg = "0" + msg + obroc = list(msg) + for i in range(l_poly16 - 1): + if obroc[i] == "0": + obroc[i] = "1" + elif obroc[i] == '1': + obroc[i] = "0" + + msg = "".join(obroc) + remainder = divide(msg, poly16) + #Poprawione sprawdzanie + suma = 0 + for i in range(0, len(remainder)): + if '1' in remainder: + suma = suma+1 + + if suma == 0: + print("true ") + elif suma > 0: + print("false") + + def encode(message, poly16): a=message @@ -134,11 +166,12 @@ def encode(message, poly16): message = "".join(obroc) remainder = divide(message, poly16) ab=binnahex(remainder) - message_final = a + ab + d=str(base64.b16decode(ab))[2:-1] + message_final = a + d message_final = bytearray(message_final, 'ascii') - ab = bytearray(ab, 'ascii') + d = bytearray(d, 'ascii') print("calosc : ", message_final) - print("crc : ", ab) + print("crc : ", d) poly16 = "10001000000100001"