1
0
forked from kalmar/DALGLI0

Update 'Zadanie3'

This commit is contained in:
Klaudia Kandulska 2018-06-21 21:10:19 +00:00
parent 2141c5b1f6
commit 5ddd10b5e2

View File

@ -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 #XOR
def xor(a, b): def xor(a, b):
@ -45,37 +51,42 @@ def divide(message, poly16):
return check return check
def encode(message, poly16): def decode(message_final,poly16):
l_poly16 = len(poly16) l_poly16 = len(poly16)
appended_message2 = message_final
# 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) remainder = divide(appended_message2, poly16)
#sprawdzenie kazdego bitu
for i in range(0, len(remainder)): for i in range(0, len(remainder)):
if '1' not in remainder: if '1' not in remainder:
print("true ") print("true ")
elif '1' in remainder:
print("false ") 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)
poly16 = "10001000000100001" poly16 = "10001000000100001"
print("podaj wiadomosc do zakodowania : ") print("podaj wiadomosc do zakodowania : ")
message = str(raw_input()) message = str(raw_input())
encode(message, poly16) encode(message, poly16)
print("podaj wiadomosc do odkodowania : ")
message2 = str(raw_input())
decode(message2, poly16)