Fix backslash issues

This commit is contained in:
Varmen8 2018-06-26 12:22:11 +02:00
parent f807d323a0
commit 3988604c14

17
main.py
View File

@ -1,5 +1,5 @@
import sys import sys
import platform
def encode(m): def encode(m):
m = bytearray(m, "ascii") m = bytearray(m, "ascii")
@ -52,9 +52,12 @@ def encode(m):
def decode(n): def decode(n):
fb = n[-7:-5] if platform.system() == "Windows":
sb = n[-2:] n = n.split("\\\\x")
msg = n[:-10] else:
n = n.split("\\x")
msg = n[0]
message = "" message = ""
for ch in msg: for ch in msg:
@ -66,12 +69,12 @@ def decode(n):
message += str(ch) message += str(ch)
fb = bin(int(fb, 16))[2:] fb = bin(int(n[1], 16))[2:]
while len(fb) < 8: while len(fb) < 8:
fb = "0" + fb fb = "0" + fb
sb = bin(int(sb, 16))[2:] sb = bin(int(n[2], 16))[2:]
while len(sb) < 8: while len(sb) < 8:
sb = "0" + sb sb = "0" + sb
@ -114,7 +117,7 @@ if __name__ == "__main__":
if len(sys.argv) < 2: if len(sys.argv) < 2:
print("Proszę wprowadzić jedną z flag:\n") print("Proszę wprowadzić jedną z flag:\n")
print(" -e, --encode\tZakoduj <wiadomość>") print(" -e, --encode\tZakoduj <wiadomość>")
print(" -d, --decode\tDekoduj <wiadomość_z_ramką>") print(" -d, --decode\tDekoduj <wiadomość_z_ramką>\n")
print("Przykład:") print("Przykład:")
print("python main.py -e abc") print("python main.py -e abc")
print("python main.py -d abc\\\\x51\\\\x4a") print("python main.py -d abc\\\\x51\\\\x4a")