-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode.py
More file actions
23 lines (20 loc) · 876 Bytes
/
encode.py
File metadata and controls
23 lines (20 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
ALPHABET = [
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z','.','0','1','2','3','4','5','6','7','8','9',
'!','@','#','$','%','^','&','*','(',')'
]
class Encode:
def __init__(self,start_text,shift):
self.end_text = ""
for char in start_text:
if char in ALPHABET:
try:
self.position = ALPHABET.index(char)
self.new_position = self.position + shift
self.end_text += ALPHABET[self.new_position]
except IndexError:
self.new_position = ALPHABET.index(char) % len(ALPHABET)
else:
self.end_text += char
self.end_text = self.end_text
print(f"Here's the result: {self.end_text}")