Zadanie3 #28

Closed
s407228 wants to merge 18 commits from s407228/DALGLI0:Zadanie3 into master
Showing only changes of commit 5ddd10b5e2 - Show all commits

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,30 +51,36 @@ 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 ")
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 : ") 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)