Update 'Zadanie3'
This commit is contained in:
parent
2a39bdbcdf
commit
b8a923877f
23
Zadanie3
23
Zadanie3
@ -86,10 +86,22 @@ def divide(message, poly16):
|
||||
return check
|
||||
|
||||
|
||||
def decode(message_final,poly16):
|
||||
def decode(message_final,poly16,crc):
|
||||
l_poly16 = len(poly16)
|
||||
appended_message2 = message_final
|
||||
remainder = divide(appended_message2, poly16)
|
||||
appended_message2 = toBinary(message_final)
|
||||
obroc = list(appended_message2)
|
||||
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)
|
||||
|
||||
dec = int(crc, 16)
|
||||
crc2=bin(dec)[2:]
|
||||
msg=appended_message2+crc2
|
||||
remainder = divide(msg, poly16)
|
||||
#Poprawione sprawdzanie
|
||||
suma = 0
|
||||
for i in range(0, len(remainder)):
|
||||
@ -101,6 +113,7 @@ def decode(message_final,poly16):
|
||||
elif suma > 0:
|
||||
print("false")
|
||||
|
||||
|
||||
|
||||
def encode(message, poly16):
|
||||
#konwersja z ascii do binarnego
|
||||
@ -135,6 +148,8 @@ def main():
|
||||
flag = argv[2]
|
||||
if flag == 'encode':
|
||||
encode(message, poly16)
|
||||
|
||||
elif flag == 'decode':
|
||||
crc = argv[3]
|
||||
decode(message, poly16,crc)
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user