-
Notifications
You must be signed in to change notification settings - Fork 0
/
caesar_encode_decode.py
76 lines (49 loc) · 1.43 KB
/
caesar_encode_decode.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
os.system('cls')
print('''
##################################################
# #
# caesar_encode by : Welson #
# #
##################################################
''')
def encode():
print('Starting encode')
print('输入你想要输入的明文' )
txt = input(">>")
print('请输入移动位数')
offset = int(input(">>"))
#考虑用户用的是字符串
result = ""
for t in txt:
n = ord(t)
n = n + offset
t2 = chr(n)
result = result + t2
print(f'加密后的字符是 {result}')
def decode():
print('Starting decode')
print('输入你要解密的密文' )
cipher = input('>>')
print("请输入秘钥.")
key = int(input('>'))
plain = ""
for c in cipher:
n = ord(c)
n = n - key
p = chr(n)
plain += p
print(f'解密后的明文是:{plain}')
running = True
while running:
print('1.Encode 2.decode 3.Exit')
sel = input(">>")
if sel == '1':
encode()
elif sel == '2':
decode()
elif sel == '3':
print("Thank you for use this app!")
running = False
else:
print('请做出正确的选择。 ')