From 3988604c140a5971428f2a8c0e1e5cb81741180d Mon Sep 17 00:00:00 2001 From: Varmen8 Date: Tue, 26 Jun 2018 12:22:11 +0200 Subject: [PATCH] Fix backslash issues --- main.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 7e94492..0526f1c 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ import sys - +import platform def encode(m): m = bytearray(m, "ascii") @@ -52,9 +52,12 @@ def encode(m): def decode(n): - fb = n[-7:-5] - sb = n[-2:] - msg = n[:-10] + if platform.system() == "Windows": + n = n.split("\\\\x") + else: + n = n.split("\\x") + + msg = n[0] message = "" for ch in msg: @@ -66,12 +69,12 @@ def decode(n): message += str(ch) - fb = bin(int(fb, 16))[2:] + fb = bin(int(n[1], 16))[2:] while len(fb) < 8: fb = "0" + fb - sb = bin(int(sb, 16))[2:] + sb = bin(int(n[2], 16))[2:] while len(sb) < 8: sb = "0" + sb @@ -114,7 +117,7 @@ if __name__ == "__main__": if len(sys.argv) < 2: print("Proszę wprowadzić jedną z flag:\n") print(" -e, --encode\tZakoduj ") - print(" -d, --decode\tDekoduj ") + print(" -d, --decode\tDekoduj \n") print("Przykład:") print("python main.py -e abc") print("python main.py -d abc\\\\x51\\\\x4a")