From 65909526af05b5af3560ac295d5b303d4deea8d5 Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Mon, 25 Jun 2018 17:53:53 +0000 Subject: [PATCH] Update 'Zadanie3' --- Zadanie3 | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/Zadanie3 b/Zadanie3 index 807c69e..d6c2191 100644 --- a/Zadanie3 +++ b/Zadanie3 @@ -1,9 +1,12 @@ -def toBinary(string): - return "".join([format(ord(char),'#010b')[2:] for char in string]) +from sys import argv def toString(binaryString): return "".join([chr(int(binaryString[i:i+8],2)) for i in range(0,len(binaryString),8)]) +def toBinary(string): + return "".join([format(ord(char),'#010b')[2:] for char in string]) + + #XOR def xor(a, b): @@ -52,16 +55,19 @@ def divide(message, poly16): def decode(message_final,poly16): - l_poly16 = len(poly16) appended_message2 = message_final remainder = divide(appended_message2, poly16) - #sprawdzenie kazdego bitu + #Poprawione sprawdzanie + suma = 0 for i in range(0, len(remainder)): - if '1' not in remainder: - print("true ") - elif '1' in remainder: - print("false ") + if '1' in remainder: + suma = suma+1 + + if suma == 0: + print("true ") + elif suma > 0: + print("false") def encode(message, poly16): @@ -70,13 +76,13 @@ def encode(message, poly16): l_poly16 = len(poly16) - # Dodaj n-1 "0" do wiadomosci + # Dodajemy n-1 "0" do wiadomosci appended_message = aa + '0'*(l_poly16-1) remainder = divide(appended_message, poly16) message_final = aa + remainder print("binarnie calosc : ", message_final) - #konwersja z ascii do binarnego + #konwersja z binarnego do ascii ab=toString(message_final) print("w ascii : ", ab) print("sprawdzenie : ") @@ -85,8 +91,13 @@ def encode(message, poly16): poly16 = "10001000000100001" -print("podaj wiadomosc do zakodowania : ") -message = str(raw_input()) -encode(message, poly16) - +def main(): + global message + message = list(argv[1]) + flag = argv[2] + if flag == 'encode': + encode(message, poly16) + +if __name__ == '__main__': + main()