1
0
forked from kalmar/DALGLI0

Update 'Zadanie3'

This commit is contained in:
Klaudia Kandulska 2018-06-29 15:49:34 +00:00
parent 7e1e1a7348
commit 066de73659

View File

@ -84,21 +84,24 @@ def divide(message, poly16):
check = temp check = temp
return check return check
def decode(message_final,poly16,crc): def decode(message,poly16,crc):
l_poly16 = len(poly16) l_poly16 = len(poly16)
appended_message2 = toBinary(message_final) message = bytearray(message, 'ascii')
obroc = list(appended_message2) 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): for i in range(l_poly16 - 1):
if obroc[i] == "0": if obroc[i] == "0":
obroc[i] = "1" obroc[i] = "1"
elif obroc[i] == '1': elif obroc[i] == '1':
obroc[i] = "0" obroc[i] = "0"
appended_message2 = "".join(obroc) msg = "".join(obroc)
dec = int(crc, 16)
crc2=bin(dec)[2:]
msg=appended_message2+crc2
remainder = divide(msg, poly16) remainder = divide(msg, poly16)
#Poprawione sprawdzanie #Poprawione sprawdzanie
suma = 0 suma = 0
@ -137,7 +140,6 @@ def encode(message, poly16):
print("calosc : ", message_final) print("calosc : ", message_final)
print("crc : ", ab) print("crc : ", ab)
poly16 = "10001000000100001" poly16 = "10001000000100001"
def main(): def main():