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