Zadanie3 #28

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

View File

@ -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,15 +55,18 @@ 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:
if '1' in remainder:
suma = suma+1
if suma == 0:
print("true ")
elif '1' in remainder:
elif suma > 0:
print("false")
@ -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())
def main():
global message
message = list(argv[1])
flag = argv[2]
if flag == 'encode':
encode(message, poly16)
if __name__ == '__main__':
main()