forked from kalmar/DALGLI0
Update 'Zadanie3'
This commit is contained in:
parent
7e1e1a7348
commit
066de73659
20
Zadanie3
20
Zadanie3
@ -84,21 +84,24 @@ def divide(message, poly16):
|
||||
check = temp
|
||||
return check
|
||||
|
||||
def decode(message_final,poly16,crc):
|
||||
def decode(message,poly16,crc):
|
||||
l_poly16 = len(poly16)
|
||||
appended_message2 = toBinary(message_final)
|
||||
obroc = list(appended_message2)
|
||||
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"
|
||||
|
||||
appended_message2 = "".join(obroc)
|
||||
msg = "".join(obroc)
|
||||
|
||||
dec = int(crc, 16)
|
||||
crc2=bin(dec)[2:]
|
||||
msg=appended_message2+crc2
|
||||
remainder = divide(msg, poly16)
|
||||
#Poprawione sprawdzanie
|
||||
suma = 0
|
||||
@ -135,8 +138,7 @@ def encode(message, poly16):
|
||||
message_final = bytearray(message_final, 'ascii')
|
||||
ab = bytearray(ab, 'ascii')
|
||||
print("calosc : ", message_final)
|
||||
print("crc : ", ab)
|
||||
|
||||
print("crc : ", ab)
|
||||
|
||||
poly16 = "10001000000100001"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user