-
Notifications
You must be signed in to change notification settings - Fork 0
/
pp.py
35 lines (29 loc) · 1.12 KB
/
pp.py
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
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']
# dirciton = input('type "encode" to encrypt type "decode" to decrypt \n')
# #text = input('text your message')
# #shift = int(input('type shift number: \n'))
# text = input('type your text \n')
# shift = int(input('shift ? \n'))
def coder(direction , text , shift):
result = ''
list = [*text]
if direction== 'encode':
for x in list:
if x in alphabet:
if alphabet.index(x)+shift > len(alphabet)-shift:
result +=alphabet[alphabet.index(x)-(len(alphabet)-shift)]
else:
result += alphabet[alphabet.index(x)+shift]
print(result)
elif direction == 'decode':
for x in list :
if x in alphabet :
result += alphabet[alphabet.index(x)-shift]
print(result)
answer = 'y'
while answer == 'y':
dirciton = input('type "encode" to encrypt type "decode" to decrypt \n')
text = input('type your text \n')
shift = int(input('shift ? \n'))
coder(direction=dirciton , text=text ,shift=shift)
answer = input('do you want to conteniue (y/n) ')