Update 'Zadanie3'

This commit is contained in:
Klaudia Kandulska 2018-06-29 16:55:21 +00:00
parent 2ba847f726
commit 1a71d479a5

View File

@ -56,8 +56,8 @@ def xor(a, b):
# dzielenie modulo 2
def divide(message, poly16):
def divide(message):
poly16 = "10001000000100001"
# Ilosc bitow dla operacji XOR 'na raz'
step = len(poly16)
@ -85,7 +85,8 @@ def divide(message, poly16):
check = temp
return check
def decode(message,poly16,crc):
def decode(message,crc):
poly16 = "10001000000100001"
l_poly16 = len(poly16)
message = bytearray(message, 'ascii')
message = format(int.from_bytes(message, "big"), "b")
@ -102,8 +103,8 @@ def decode(message,poly16,crc):
obroc[i] = "0"
msg = "".join(obroc)
remainder = divide(msg, poly16)
#Poprawione sprawdzanie
remainder = divide(msg)
suma = 0
for i in range(0, len(remainder)):
if '1' in remainder:
@ -112,11 +113,11 @@ def decode(message,poly16,crc):
if suma == 0:
print("true ")
elif suma > 0:
print("false")
print("false",remainder)
def encode(message, poly16):
def encode(message):
poly16 = "10001000000100001"
a=message
message = bytearray(message, 'ascii')
@ -133,7 +134,7 @@ def encode(message, poly16):
obroc[i] = "0"
message = "".join(obroc)
remainder = divide(message, poly16)
remainder = divide(message)
ab=binnahex(remainder)
d=str(base64.b16decode(ab))[2:-1]
message_final = a + d
@ -143,17 +144,15 @@ def encode(message, poly16):
print("crc hex : ", ab)
print("crc ascii : ", d)
poly16 = "10001000000100001"
def main():
global message
message = list(argv[1])
flag = argv[2]
if flag == 'encode':
encode(sys.argv[1], poly16)
encode(sys.argv[1])
elif flag == 'decode':
crc = argv[3]
decode(sys.argv[1], poly16,sys.argv[3])
decode(sys.argv[1],sys.argv[3])
if __name__ == '__main__':
main()