Zadanie3 #28
20
Zadanie3
20
Zadanie3
@ -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
|
||||||
@ -135,8 +138,7 @@ def encode(message, poly16):
|
|||||||
message_final = bytearray(message_final, 'ascii')
|
message_final = bytearray(message_final, 'ascii')
|
||||||
ab = bytearray(ab, 'ascii')
|
ab = bytearray(ab, 'ascii')
|
||||||
print("calosc : ", message_final)
|
print("calosc : ", message_final)
|
||||||
print("crc : ", ab)
|
print("crc : ", ab)
|
||||||
|
|
||||||
|
|
||||||
poly16 = "10001000000100001"
|
poly16 = "10001000000100001"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user