Skip to content

Commit 87f2c3f

Browse files
committed
xortool-xor: Use bytes and py3 functions more
1 parent e802b0d commit 87f2c3f

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

‎xortool/xortool-xor‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ import string
2323
import sys
2424

2525

26-
HEXES = set("0123456789abcdefABCDEF")
27-
28-
2926
def main():
3027
cycle = True
3128
newline = True
@@ -71,20 +68,10 @@ def xor(args, cycle=True):
7168

7269

7370
def from_str(s):
74-
res = []
75-
i = 0
76-
while True:
77-
if i + 4 > len(s):
78-
break
79-
80-
if s[i] == "\\" and s[i+1] == "x" and s[i+2] in HEXES and s[i+3] in HEXES:
81-
res.append(int(s[i+2:i+4], 16))
82-
i += 4
83-
else:
84-
res.append(ord(s[i]))
85-
i += 1
86-
res += s[i:].encode("ascii")
87-
return bytes(res)
71+
res = b''
72+
for char in s.encode("utf-8").decode("unicode_escape"):
73+
res += bytes([ord(char)])
74+
return res
8875

8976

9077
def from_file(s):

0 commit comments

Comments
 (0)