Zadanie3 #28
39
Zadanie3
39
Zadanie3
@ -1,9 +1,12 @@
|
|||||||
def toBinary(string):
|
from sys import argv
|
||||||
return "".join([format(ord(char),'#010b')[2:] for char in string])
|
|
||||||
|
|
||||||
def toString(binaryString):
|
def toString(binaryString):
|
||||||
return "".join([chr(int(binaryString[i:i+8],2)) for i in range(0,len(binaryString),8)])
|
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
|
#XOR
|
||||||
def xor(a, b):
|
def xor(a, b):
|
||||||
|
|
||||||
@ -52,16 +55,19 @@ def divide(message, poly16):
|
|||||||
|
|
||||||
|
|
||||||
def decode(message_final,poly16):
|
def decode(message_final,poly16):
|
||||||
|
|
||||||
l_poly16 = len(poly16)
|
l_poly16 = len(poly16)
|
||||||
appended_message2 = message_final
|
appended_message2 = message_final
|
||||||
remainder = divide(appended_message2, poly16)
|
remainder = divide(appended_message2, poly16)
|
||||||
#sprawdzenie kazdego bitu
|
#Poprawione sprawdzanie
|
||||||
|
suma = 0
|
||||||
for i in range(0, len(remainder)):
|
for i in range(0, len(remainder)):
|
||||||
if '1' not in remainder:
|
if '1' in remainder:
|
||||||
print("true ")
|
suma = suma+1
|
||||||
elif '1' in remainder:
|
|
||||||
print("false ")
|
if suma == 0:
|
||||||
|
print("true ")
|
||||||
|
elif suma > 0:
|
||||||
|
print("false")
|
||||||
|
|
||||||
|
|
||||||
def encode(message, poly16):
|
def encode(message, poly16):
|
||||||
@ -70,13 +76,13 @@ def encode(message, poly16):
|
|||||||
|
|
||||||
l_poly16 = len(poly16)
|
l_poly16 = len(poly16)
|
||||||
|
|
||||||
# Dodaj n-1 "0" do wiadomosci
|
# 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)
|
remainder = divide(appended_message, poly16)
|
||||||
|
|
||||||
message_final = aa + remainder
|
message_final = aa + remainder
|
||||||
print("binarnie calosc : ", message_final)
|
print("binarnie calosc : ", message_final)
|
||||||
#konwersja z ascii do binarnego
|
#konwersja z binarnego do ascii
|
||||||
ab=toString(message_final)
|
ab=toString(message_final)
|
||||||
print("w ascii : ", ab)
|
print("w ascii : ", ab)
|
||||||
print("sprawdzenie : ")
|
print("sprawdzenie : ")
|
||||||
@ -85,8 +91,13 @@ def encode(message, poly16):
|
|||||||
|
|
||||||
|
|
||||||
poly16 = "10001000000100001"
|
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user