-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathed.py
More file actions
29 lines (27 loc) · 736 Bytes
/
ed.py
File metadata and controls
29 lines (27 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import re
class encodedecode():
def __init__(self, badchars):
badchars = list(badchars)
badchars.append("[")
badchars.append("]")
self.badchars = badchars
def encode(self, text):
text = list(text)
newtext = ""
for char in text:
if char in self.badchars:
newtext+=f"[{ord(char)}]"
else:
newtext+=char
return newtext
def decode(self, text):
newtext = text
matches = re.findall(r"\[.*?\]", newtext)
for match in matches:
n = match[1:-1]
print(n)
if n.isdigit():
n = int(n)
newtext = newtext.replace(match, chr(n), 1)
return newtext
ed = encodedecode("/") # This is just for this project, do not need to include if copying