1
0
forked from kalmar/DALGLI0

Update 'Zadanie3'

This commit is contained in:
Klaudia Kandulska 2018-06-27 23:07:44 +00:00
parent 2a39bdbcdf
commit b8a923877f

View File

@ -86,10 +86,22 @@ def divide(message, poly16):
return check return check
def decode(message_final,poly16): def decode(message_final,poly16,crc):
l_poly16 = len(poly16) l_poly16 = len(poly16)
appended_message2 = message_final appended_message2 = toBinary(message_final)
remainder = divide(appended_message2, poly16) 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 #Poprawione sprawdzanie
suma = 0 suma = 0
for i in range(0, len(remainder)): for i in range(0, len(remainder)):
@ -102,6 +114,7 @@ def decode(message_final,poly16):
print("false") print("false")
def encode(message, poly16): def encode(message, poly16):
#konwersja z ascii do binarnego #konwersja z ascii do binarnego
aa=toBinary(message) aa=toBinary(message)
@ -135,6 +148,8 @@ def main():
flag = argv[2] flag = argv[2]
if flag == 'encode': if flag == 'encode':
encode(message, poly16) encode(message, poly16)
elif flag == 'decode':
crc = argv[3]
decode(message, poly16,crc)
if __name__ == '__main__': if __name__ == '__main__':
main() main()