-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecoder.py
More file actions
41 lines (33 loc) · 983 Bytes
/
Copy pathdecoder.py
File metadata and controls
41 lines (33 loc) · 983 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
30
31
32
33
34
35
36
37
38
39
40
41
import sys
class Decoder:
def __init__(self):
self.data = None
self.new = ""
def decode(self, data):
self.data = data
for char in data:
if ord(char) < 32 or ord(char) > 126:
print(f"Invalid character: {char} (ASCII: {ord(char)})")
continue
else:
self.new += (chr(ord(char) - 7))
return self.data
def __str__(self):
return f"Decoder(data={self.new})"
def main():
# printable ascci characters
# 32-126
while True:
try:
decoder = Decoder()
data = input("Enter a string to decode: ")
if not data:
print("No data provided.")
sys.exit(1)
decoder.decode(data)
print("Decoded data:", decoder.new)
except EOFError:
print("\nExiting...")
sys.exit(0)
if __name__ == "__main__":
main()