From 7fcd497e1f142615f8d5ca831231f85e51524830 Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Wed, 6 Jun 2018 20:54:04 +0000 Subject: [PATCH 01/18] Dodaj 'Wielomiany' --- Wielomiany | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Wielomiany diff --git a/Wielomiany b/Wielomiany new file mode 100644 index 0000000..b34dd39 --- /dev/null +++ b/Wielomiany @@ -0,0 +1,67 @@ +#include +#include + +using namespace std; + + +int *iloczyn(int A[], int B[], int m, int n) +{ + int *w = new int[m+n-1]; + for (int i = 0; i>x; + int a,b; + cout <<"Podaj stopien wielomianu 1: "; + cin >> a; + cout <<"Podaj stopien wielomianu 2: "; + cin >> b; + int A[a]; + int B[b]; + for (int i=0;i> A[i]; + + } + for (int j=0;j> B[j]; + + } + int *przyklad = iloczyn(A, B, a+1, b+1); + cout << "Wynik: " ; + Wypisz(przyklad, a+b+1, x); + cout < Date: Fri, 8 Jun 2018 14:22:53 +0000 Subject: [PATCH 02/18] =?UTF-8?q?Usu=C5=84=20'Wielomiany'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Wielomiany | 67 ------------------------------------------------------ 1 file changed, 67 deletions(-) delete mode 100644 Wielomiany diff --git a/Wielomiany b/Wielomiany deleted file mode 100644 index b34dd39..0000000 --- a/Wielomiany +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include - -using namespace std; - - -int *iloczyn(int A[], int B[], int m, int n) -{ - int *w = new int[m+n-1]; - for (int i = 0; i>x; - int a,b; - cout <<"Podaj stopien wielomianu 1: "; - cin >> a; - cout <<"Podaj stopien wielomianu 2: "; - cin >> b; - int A[a]; - int B[b]; - for (int i=0;i> A[i]; - - } - for (int j=0;j> B[j]; - - } - int *przyklad = iloczyn(A, B, a+1, b+1); - cout << "Wynik: " ; - Wypisz(przyklad, a+b+1, x); - cout < Date: Wed, 20 Jun 2018 21:29:22 +0000 Subject: [PATCH 03/18] Zadanie3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wersja 1, dla wielomianów przedstawionych binarnie, bez ascii --- Zadanie3 | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Zadanie3 diff --git a/Zadanie3 b/Zadanie3 new file mode 100644 index 0000000..3569a86 --- /dev/null +++ b/Zadanie3 @@ -0,0 +1,77 @@ +#XOR +def xor(a, b): + + # init + result = [] + + # porownuje znaki + for i in range(1, len(b)): + if a[i] == b[i]: + result.append('0') + else: + result.append('1') + + return ''.join(result) + + +# dzielenie modulo 2 +def divide(message, poly16): + + # Ilosc bitow dla operacji XOR 'na raz' + step = len(poly16) + + # podzial krok po kroku + temp = message[0 : step] + + while step < len(message): + + if temp[0] == '1': + + temp = xor(poly16, temp) + message[step] + + else: + # jezeli 1 bit po lewej == 0 + temp = xor('0'*step, temp) + message[step] + + # kolejny krok + step += 1 + + if temp[0] == '1': + temp = xor(poly16, temp) + else: + temp = xor('0'*step, temp) + + check = temp + return check + + +def encode(message, poly16): + + l_poly16 = len(poly16) + + # Dodajemy n-1 "0" do wiadomosci + appended_message = message + '0'*(l_poly16-1) + remainder = divide(appended_message, poly16) + + message_final = message + remainder + print("calosc : ", + message_final) + + + +def decode(message2, poly16): + + l_poly16 = len(poly16) + appended_message2 = message2 + remainder = divide(appended_message2, poly16) + print("reszta : ", remainder) + + + +poly16 = "10001000000100001" +print("podaj wiadomosc do zakodowania : ") +message = str(raw_input()) +encode(message, poly16) +print("podaj wiadomosc do odkodowania : ") +message2 = str(raw_input()) +decode(message2, poly16) -- 2.20.1 From 2141c5b1f6270208a26b181c2a5bfe95ea1ba38b Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Thu, 21 Jun 2018 12:48:23 +0000 Subject: [PATCH 04/18] Update 'Zadanie3' true/false dla reszty --- Zadanie3 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Zadanie3 b/Zadanie3 index 3569a86..8780d01 100644 --- a/Zadanie3 +++ b/Zadanie3 @@ -46,7 +46,8 @@ def divide(message, poly16): def encode(message, poly16): - + + l_poly16 = len(poly16) # Dodajemy n-1 "0" do wiadomosci @@ -64,7 +65,10 @@ def decode(message2, poly16): l_poly16 = len(poly16) appended_message2 = message2 remainder = divide(appended_message2, poly16) - print("reszta : ", remainder) + for i in range(0, len(remainder)): + if '1' not in remainder: + print("true ") + print("false ") -- 2.20.1 From 5ddd10b5e27ba08b195f0f010b1f3da21d1b71d9 Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Thu, 21 Jun 2018 21:10:19 +0000 Subject: [PATCH 05/18] Update 'Zadanie3' --- Zadanie3 | 53 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/Zadanie3 b/Zadanie3 index 8780d01..807c69e 100644 --- a/Zadanie3 +++ b/Zadanie3 @@ -1,3 +1,9 @@ +def toBinary(string): + return "".join([format(ord(char),'#010b')[2:] for char in string]) + +def toString(binaryString): + return "".join([chr(int(binaryString[i:i+8],2)) for i in range(0,len(binaryString),8)]) + #XOR def xor(a, b): @@ -44,31 +50,37 @@ def divide(message, poly16): check = temp return check - -def encode(message, poly16): +def decode(message_final,poly16): l_poly16 = len(poly16) - - # Dodajemy n-1 "0" do wiadomosci - appended_message = message + '0'*(l_poly16-1) - remainder = divide(appended_message, poly16) - - message_final = message + remainder - print("calosc : ", - message_final) - - - -def decode(message2, poly16): - - l_poly16 = len(poly16) - appended_message2 = message2 + appended_message2 = message_final remainder = divide(appended_message2, poly16) + #sprawdzenie kazdego bitu for i in range(0, len(remainder)): if '1' not in remainder: print("true ") - print("false ") + elif '1' in remainder: + print("false ") + + +def encode(message, poly16): + #konwersja z ascii do binarnego + aa=toBinary(message) + + l_poly16 = len(poly16) + + # Dodaj 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 + ab=toString(message_final) + print("w ascii : ", ab) + print("sprawdzenie : ") + decode(message_final, poly16) @@ -76,6 +88,5 @@ poly16 = "10001000000100001" print("podaj wiadomosc do zakodowania : ") message = str(raw_input()) encode(message, poly16) -print("podaj wiadomosc do odkodowania : ") -message2 = str(raw_input()) -decode(message2, poly16) + + -- 2.20.1 From 65909526af05b5af3560ac295d5b303d4deea8d5 Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Mon, 25 Jun 2018 17:53:53 +0000 Subject: [PATCH 06/18] 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() -- 2.20.1 From 2a39bdbcdf3cd7920fd3056a96e689cc49ac2306 Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Wed, 27 Jun 2018 21:30:58 +0000 Subject: [PATCH 07/18] Zadanie3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Encode wygląda okej --- Zadanie3 | 65 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/Zadanie3 b/Zadanie3 index d6c2191..1de6255 100644 --- a/Zadanie3 +++ b/Zadanie3 @@ -1,11 +1,43 @@ 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]) +def binnahex(var): + all = {"0000": "0", + "0001": "1", + "0010": "2", + "0011": "3", + "0100": "4", + "0101": "5", + "0110": "6", + "0111": "7", + "1000": "8", + "1001": "9", + "1010": "A", + "1011": "B", + "1100": "C", + "1101": "D", + "1110": "E", + "1111": "F" + } + i = 0 + output = "" + + while (len(var) % 4 != 0): + var = "0" + var + + while (i < len(var)): + output = output + all[var[i:i + 4]] + i = i + 4 + + output = output.lstrip("0") + output = "0" if len(output) == 0 else output + + return output + +def toString(binaryString): + return "".join([chr(int(binaryString[i:i+8],2)) for i in range(0,len(binaryString),8)]) #XOR def xor(a, b): @@ -73,20 +105,25 @@ def decode(message_final,poly16): def encode(message, poly16): #konwersja z ascii do binarnego aa=toBinary(message) - + a=toString(aa) l_poly16 = len(poly16) - + + obroc = list(aa) + for i in range(l_poly16 - 1): + if obroc[i] == "0": + obroc[i] = "1" + elif obroc[i] == '1': + obroc[i] = "0" + + aa = "".join(obroc) + # Dodajemy n-1 "0" do wiadomosci - appended_message = aa + '0'*(l_poly16-1) + appended_message = aa + '0'*(l_poly16-1) remainder = divide(appended_message, poly16) - - message_final = aa + remainder - print("binarnie calosc : ", message_final) - #konwersja z binarnego do ascii - ab=toString(message_final) - print("w ascii : ", ab) - print("sprawdzenie : ") - decode(message_final, poly16) + ab=binnahex(remainder) + message_final = a + ab + print("calosc : ", message_final) + print("crc : ", ab) -- 2.20.1 From b8a923877f07cce32ebc0c428d98f734d2b452d3 Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Wed, 27 Jun 2018 23:07:44 +0000 Subject: [PATCH 08/18] 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() -- 2.20.1 From 7e1e1a73489df4762090095a7d18f95f99a040c4 Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Fri, 29 Jun 2018 15:36:03 +0000 Subject: [PATCH 09/18] Update 'Zadanie3' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Encode jako bytearray, decode wciąż działa wybiórczo --- Zadanie3 | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/Zadanie3 b/Zadanie3 index dc531f5..1be6210 100644 --- a/Zadanie3 +++ b/Zadanie3 @@ -1,4 +1,6 @@ from sys import argv +import sys +import binascii def toBinary(string): return "".join([format(ord(char),'#010b')[2:] for char in string]) @@ -36,9 +38,6 @@ def binnahex(var): return output -def toString(binaryString): - return "".join([chr(int(binaryString[i:i+8],2)) for i in range(0,len(binaryString),8)]) - #XOR def xor(a, b): @@ -85,7 +84,6 @@ def divide(message, poly16): check = temp return check - def decode(message_final,poly16,crc): l_poly16 = len(poly16) appended_message2 = toBinary(message_final) @@ -113,31 +111,31 @@ def decode(message_final,poly16,crc): elif suma > 0: print("false") - - def encode(message, poly16): - #konwersja z ascii do binarnego - aa=toBinary(message) - a=toString(aa) + + a=message + + message = bytearray(message, 'ascii') + message = format(int.from_bytes(message, "big"), "b") l_poly16 = len(poly16) - - obroc = list(aa) + message = message + '0'*(l_poly16-1) + while len(message) % 8 != 0: + message = "0" + message + obroc = list(message) for i in range(l_poly16 - 1): if obroc[i] == "0": obroc[i] = "1" elif obroc[i] == '1': obroc[i] = "0" - aa = "".join(obroc) - - # Dodajemy n-1 "0" do wiadomosci - appended_message = aa + '0'*(l_poly16-1) - remainder = divide(appended_message, poly16) + message = "".join(obroc) + remainder = divide(message, poly16) ab=binnahex(remainder) message_final = a + ab + message_final = bytearray(message_final, 'ascii') + ab = bytearray(ab, 'ascii') print("calosc : ", message_final) - print("crc : ", ab) - + print("crc : ", ab) poly16 = "10001000000100001" @@ -147,9 +145,9 @@ def main(): message = list(argv[1]) flag = argv[2] if flag == 'encode': - encode(message, poly16) + encode(sys.argv[1], poly16) elif flag == 'decode': crc = argv[3] - decode(message, poly16,crc) + decode(sys.argv[1], poly16,sys.argv[3]) if __name__ == '__main__': main() -- 2.20.1 From 066de73659c67fd5607489575df7cb020b35429c Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Fri, 29 Jun 2018 15:49:34 +0000 Subject: [PATCH 10/18] Update 'Zadanie3' --- Zadanie3 | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Zadanie3 b/Zadanie3 index 1be6210..bcc7acd 100644 --- a/Zadanie3 +++ b/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" -- 2.20.1 From c624158b500bd35db74412fab046602453c385d5 Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Fri, 29 Jun 2018 16:16:51 +0000 Subject: [PATCH 11/18] Update 'Zadanie3' --- Zadanie3 | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/Zadanie3 b/Zadanie3 index bcc7acd..6186275 100644 --- a/Zadanie3 +++ b/Zadanie3 @@ -1,6 +1,7 @@ from sys import argv import sys import binascii +import base64 def toBinary(string): return "".join([format(ord(char),'#010b')[2:] for char in string]) @@ -101,7 +102,8 @@ def decode(message,poly16,crc): obroc[i] = "0" msg = "".join(obroc) - + print(msg) + print(crc2) remainder = divide(msg, poly16) #Poprawione sprawdzanie suma = 0 @@ -114,6 +116,36 @@ def decode(message,poly16,crc): elif suma > 0: print("false") +def decode(message,poly16,crc): + l_poly16 = len(poly16) + 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" + + msg = "".join(obroc) + remainder = divide(msg, poly16) + #Poprawione sprawdzanie + suma = 0 + for i in range(0, len(remainder)): + if '1' in remainder: + suma = suma+1 + + if suma == 0: + print("true ") + elif suma > 0: + print("false") + + def encode(message, poly16): a=message @@ -134,11 +166,12 @@ def encode(message, poly16): message = "".join(obroc) remainder = divide(message, poly16) ab=binnahex(remainder) - message_final = a + ab + d=str(base64.b16decode(ab))[2:-1] + message_final = a + d message_final = bytearray(message_final, 'ascii') - ab = bytearray(ab, 'ascii') + d = bytearray(d, 'ascii') print("calosc : ", message_final) - print("crc : ", ab) + print("crc : ", d) poly16 = "10001000000100001" -- 2.20.1 From 504f4a3c5a94b4b084d7bd85fcd9aaa795620a2c Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Fri, 29 Jun 2018 16:26:06 +0000 Subject: [PATCH 12/18] Update 'Zadanie3' --- Zadanie3 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Zadanie3 b/Zadanie3 index 6186275..59ad2f0 100644 --- a/Zadanie3 +++ b/Zadanie3 @@ -89,8 +89,8 @@ def decode(message,poly16,crc): l_poly16 = len(poly16) message = bytearray(message, 'ascii') message = format(int.from_bytes(message, "big"), "b") - dec = int(crc, 16) - crc2=bin(dec)[2:] + crc2=binascii.unhexlify(crc) + print(crc2) msg=message+crc2 while len(msg) % 8 != 0: msg = "0" + msg @@ -171,7 +171,8 @@ def encode(message, poly16): message_final = bytearray(message_final, 'ascii') d = bytearray(d, 'ascii') print("calosc : ", message_final) - print("crc : ", d) + print("crc hex : ", ab) + print("crc ascii : ", d) poly16 = "10001000000100001" -- 2.20.1 From 2ba847f726987a79d122f24b4fa31972673e9da0 Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Fri, 29 Jun 2018 16:27:46 +0000 Subject: [PATCH 13/18] Update 'Zadanie3' --- Zadanie3 | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/Zadanie3 b/Zadanie3 index 59ad2f0..683269f 100644 --- a/Zadanie3 +++ b/Zadanie3 @@ -85,37 +85,6 @@ def divide(message, poly16): check = temp return check -def decode(message,poly16,crc): - l_poly16 = len(poly16) - message = bytearray(message, 'ascii') - message = format(int.from_bytes(message, "big"), "b") - crc2=binascii.unhexlify(crc) - print(crc2) - 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" - - msg = "".join(obroc) - print(msg) - print(crc2) - remainder = divide(msg, poly16) - #Poprawione sprawdzanie - suma = 0 - for i in range(0, len(remainder)): - if '1' in remainder: - suma = suma+1 - - if suma == 0: - print("true ") - elif suma > 0: - print("false") - def decode(message,poly16,crc): l_poly16 = len(poly16) message = bytearray(message, 'ascii') @@ -187,3 +156,4 @@ def main(): decode(sys.argv[1], poly16,sys.argv[3]) if __name__ == '__main__': main() + -- 2.20.1 From 1a71d479a531653c20963d080b7695d87f6431ea Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Fri, 29 Jun 2018 16:55:21 +0000 Subject: [PATCH 14/18] Update 'Zadanie3' --- Zadanie3 | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Zadanie3 b/Zadanie3 index 683269f..5a5f5bc 100644 --- a/Zadanie3 +++ b/Zadanie3 @@ -56,8 +56,8 @@ def xor(a, b): # dzielenie modulo 2 -def divide(message, poly16): - +def divide(message): + poly16 = "10001000000100001" # Ilosc bitow dla operacji XOR 'na raz' step = len(poly16) @@ -85,7 +85,8 @@ def divide(message, poly16): check = temp return check -def decode(message,poly16,crc): +def decode(message,crc): + poly16 = "10001000000100001" l_poly16 = len(poly16) message = bytearray(message, 'ascii') message = format(int.from_bytes(message, "big"), "b") @@ -102,8 +103,8 @@ def decode(message,poly16,crc): obroc[i] = "0" msg = "".join(obroc) - remainder = divide(msg, poly16) - #Poprawione sprawdzanie + remainder = divide(msg) + suma = 0 for i in range(0, len(remainder)): if '1' in remainder: @@ -112,11 +113,11 @@ def decode(message,poly16,crc): if suma == 0: print("true ") elif suma > 0: - print("false") + print("false",remainder) -def encode(message, poly16): - +def encode(message): + poly16 = "10001000000100001" a=message message = bytearray(message, 'ascii') @@ -133,7 +134,7 @@ def encode(message, poly16): obroc[i] = "0" message = "".join(obroc) - remainder = divide(message, poly16) + remainder = divide(message) ab=binnahex(remainder) d=str(base64.b16decode(ab))[2:-1] message_final = a + d @@ -143,17 +144,15 @@ def encode(message, poly16): print("crc hex : ", ab) print("crc ascii : ", d) -poly16 = "10001000000100001" def main(): global message message = list(argv[1]) flag = argv[2] if flag == 'encode': - encode(sys.argv[1], poly16) + encode(sys.argv[1]) elif flag == 'decode': crc = argv[3] - decode(sys.argv[1], poly16,sys.argv[3]) + decode(sys.argv[1],sys.argv[3]) if __name__ == '__main__': main() - -- 2.20.1 From e5905c0a8a32dd26c491d8360ff3841238bd2b74 Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Fri, 29 Jun 2018 16:57:17 +0000 Subject: [PATCH 15/18] Update 'Zadanie3' --- Zadanie3 | 3 --- 1 file changed, 3 deletions(-) diff --git a/Zadanie3 b/Zadanie3 index 5a5f5bc..e5577f8 100644 --- a/Zadanie3 +++ b/Zadanie3 @@ -3,9 +3,6 @@ import sys import binascii import base64 -def toBinary(string): - return "".join([format(ord(char),'#010b')[2:] for char in string]) - def binnahex(var): all = {"0000": "0", "0001": "1", -- 2.20.1 From ddb7a240f44ea1659fd733e237d7f5b89100860b Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Fri, 29 Jun 2018 17:13:42 +0000 Subject: [PATCH 16/18] Update 'Zadanie3' --- Zadanie3 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Zadanie3 b/Zadanie3 index e5577f8..9299029 100644 --- a/Zadanie3 +++ b/Zadanie3 @@ -100,6 +100,7 @@ def decode(message,crc): obroc[i] = "0" msg = "".join(obroc) + remainder = divide(msg) suma = 0 @@ -140,7 +141,7 @@ def encode(message): print("calosc : ", message_final) print("crc hex : ", ab) print("crc ascii : ", d) - + decode(a,ab) def main(): global message -- 2.20.1 From 1dc92f3872238456ab17c4f772388faab5d600ef Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Fri, 29 Jun 2018 17:42:53 +0000 Subject: [PATCH 17/18] Update 'Zadanie3' --- Zadanie3 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Zadanie3 b/Zadanie3 index 9299029..aa3ef98 100644 --- a/Zadanie3 +++ b/Zadanie3 @@ -111,7 +111,7 @@ def decode(message,crc): if suma == 0: print("true ") elif suma > 0: - print("false",remainder) + print("false") def encode(message): @@ -153,4 +153,4 @@ def main(): crc = argv[3] decode(sys.argv[1],sys.argv[3]) if __name__ == '__main__': - main() + main() \ No newline at end of file -- 2.20.1 From 9c6a607f3451efeed13074a53a4144841d115e8a Mon Sep 17 00:00:00 2001 From: Klaudia Kandulska Date: Fri, 29 Jun 2018 21:11:50 +0000 Subject: [PATCH 18/18] Update 'Zadanie3' --- Zadanie3 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Zadanie3 b/Zadanie3 index aa3ef98..ff3ee5b 100644 --- a/Zadanie3 +++ b/Zadanie3 @@ -87,8 +87,12 @@ def decode(message,crc): l_poly16 = len(poly16) message = bytearray(message, 'ascii') message = format(int.from_bytes(message, "big"), "b") + while len(message) % 8 != 0: + message = "0" + message dec = int(crc, 16) crc2=bin(dec)[2:] + while len(crc2) % 8 != 0: + crc2 = "0" + crc2 msg=message+crc2 while len(msg) % 8 != 0: msg = "0" + msg @@ -153,4 +157,4 @@ def main(): crc = argv[3] decode(sys.argv[1],sys.argv[3]) if __name__ == '__main__': - main() \ No newline at end of file + main() -- 2.20.1