新Python项目:替换式密码
本文最后更新于 1243 天前,其中的信息可能已经有所发展或是发生改变。

2022 Update:警示后人:不查自带函数的后果很严重! 额…发现可以把文字转码后+1/-1来实现

最近我才学定义函数,写了一个替换式密码小程序。

1.替换式密码.py

这个程序是可以被调用的,一共有两个函数,分别是jiami”(加密)jiemi(解密)。jiami调用时传入两个参数,第一个是明文,第二个是移位值,传回密文。jiemi调用时也传入两个参数,第一个是密文,第二个是移位值,传回明文。

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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# 文件名:替换式密码.py

# 包括两个函数

def jiami(ming, yi):
mi = ""
ming_old_list = list(ming)
ming = ""
for y in range(0, yi):
for i in ming_old_list:
if i == "a":
mi += "b"
elif i == "A":
mi += "B"

elif i == "b":
mi += "c"
elif i == "B":
mi += "C"

elif i == "c":
mi += "d"
elif i == "C":
mi += "D"

elif i == "d":
mi += "e"
elif i == "D":
mi += "E"

elif i == "e":
mi += "f"
elif i == "E":
mi += "F"

elif i == "f":
mi += "g"
elif i == "F":
mi += "G"

elif i == "g":
mi += "h"
elif i == "G":
mi += "H"

elif i == "h":
mi += "i"
elif i == "H":
mi += "I"

elif i == "i":
mi += "j"
elif i == "I":
mi += "J"

elif i == "j":
mi += "k"
elif i == "J":
mi += "K"

elif i == "k":
mi += "l"
elif i == "K":
mi += "L"

elif i == "l":
mi += "m"
elif i == "L":
mi += "M"

elif i == "m":
mi += "n"
elif i == "M":
mi += "N"

elif i == "n":
mi += "o"
elif i == "N":
mi += "O"

elif i == "o":
mi += "p"
elif i == "O":
mi += "P"

elif i == "p":
mi += "q"
elif i == "P":
mi += "Q"

elif i == "q":
mi += "r"
elif i == "Q":
mi += "R"

elif i == "r":
mi += "s"
elif i == "R":
mi += "S"

elif i == "s":
mi += "t"
elif i == "S":
mi += "T"

elif i == "t":
mi += "u"
elif i == "T":
mi += "U"

elif i == "u":
mi += "v"
elif i == "U":
mi += "V"

elif i == "v":
mi += "w"
elif i == "V":
mi += "W"

elif i == "w":
mi += "x"
elif i == "W":
mi += "X"

elif i == "x":
mi += "y"
elif i == "X":
mi += "Y"

elif i == "y":
mi += "z"
elif i == "Y":
mi += "Z"

elif i == "z":
mi += "a"
elif i == "Z":
mi += "A"

else:
mi += i
ming_old_list = list(mi)
mi_str = mi
mi = ""
return mi_str


def jiemi(mi, yi):
ming = ""
mi_old_list = list(mi)
mi = ""
for y in range(0, yi):
for i in mi_old_list:
if i == "a":
ming += "z"
elif i == "A":
ming += "Z"

elif i == "b":
ming += "a"
elif i == "B":
ming += "A"

elif i == "c":
ming += "b"
elif i == "C":
ming += "B"

elif i == "d":
ming += "c"
elif i == "D":
ming += "C"

elif i == "e":
ming += "d"
elif i == "E":
ming += "D"

elif i == "f":
ming += "e"
elif i == "F":
ming += "E"

elif i == "g":
ming += "f"
elif i == "G":
ming += "F"

elif i == "h":
ming += "g"
elif i == "H":
ming += "G"

elif i == "i":
ming += "h"
elif i == "I":
ming += "H"

elif i == "j":
ming += "i"
elif i == "J":
ming += "I"

elif i == "k":
ming += "j"
elif i == "K":
ming += "J"

elif i == "l":
ming += "k"
elif i == "L":
ming += "K"

elif i == "m":
ming += "l"
elif i == "M":
ming += "L"

elif i == "n":
ming += "m"
elif i == "N":
ming += "M"

elif i == "o":
ming += "n"
elif i == "O":
ming += "N"

elif i == "p":
ming += "o"
elif i == "P":
ming += "O"

elif i == "q":
ming += "p"
elif i == "Q":
ming += "P"

elif i == "r":
ming += "q"
elif i == "R":
ming += "Q"

elif i == "s":
ming += "r"
elif i == "S":
ming += "R"

elif i == "t":
ming += "s"
elif i == "T":
ming += "S"

elif i == "u":
ming += "t"
elif i == "U":
ming += "T"

elif i == "v":
ming += "u"
elif i == "V":
ming += "U"

elif i == "w":
ming += "v"
elif i == "W":
ming += "V"

elif i == "x":
ming += "w"
elif i == "X":
ming += "W"

elif i == "y":
ming += "x"
elif i == "Y":
ming += "X"

elif i == "z":
ming += "y"
elif i == "Z":
ming += "Y"

else:
ming += i
mi_old_list = list(ming)
ming_str = ming
ming = ""
return ming_str

2.文本替换式加解密.py

这个Python程序可以引导你加/解密

运行效果

代码来喽!

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
# 依赖替换式密码

# 文件名:文本替换式加解密.py

import 替换式密码

while True:
print("欢迎使用文本加解密APP!")
print("(1)加密 (2)解密 输入其他内容退出")
m = input("请输入:")
if m == "1":
ming = input("请输入明文:")
while True:
try:
yi = int(input("请输入移位值:"))
except ValueError:
print("请输入数字!")
else:
break
print("密文为:{a638d642d867b568c1aede4e6cc48965ba83a47abef8f643eb9348429a71096e}s\n" {a638d642d867b568c1aede4e6cc48965ba83a47abef8f643eb9348429a71096e} (替换式密码.jiami(ming, yi)))

elif m == "2":
mi = input("请输入密文:")
while True:
try:
yi = int(input("请输入移位值:"))
except ValueError:
print("请输入数字!")
else:
break
print("明文为:{a638d642d867b568c1aede4e6cc48965ba83a47abef8f643eb9348429a71096e}s\n" {a638d642d867b568c1aede4e6cc48965ba83a47abef8f643eb9348429a71096e} (替换式密码.jiemi(mi, yi)))

else:
break
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇