From b8a923877f07cce32ebc0c428d98f734d2b452d3 Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Wed, 27 Jun 2018 23:07:44 +0000 Subject: [PATCH] Update 'Zadanie3' --- Zadanie3 | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Zadanie3 b/Zadanie3 index 1de6255..dc531f5 100644 --- a/Zadanie3 +++ b/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()