Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson7_4
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
de8c54f3
authored
Aug 17, 2025
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
1c197d62
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
11 deletions
1答案.py
diy4.py
1答案.py
0 → 100644
View file @
de8c54f3
import
random
#导入随机数
import
random
#导入随机数
# 私钥
key
=
"abcdefgh使用python实现简单的位移替换加密,制作密码机关真是太好玩了哈哈哈!"
# 要加密语句
message
=
"诺依,周末一起去看动漫展吧!"
#message消息
# 最终加密后的语句
key_message
=
""
noise
=
"port:@#$
%
^&"
# 干扰字符
for
i
in
message
:
#for循环遍历
str1
=
i
#str字符串
str2
=
random
.
choice
(
key
)
#随机选择加入
str3
=
random
.
choice
(
key
)
#随机选择加入
text
=
str1
+
str2
+
str3
#text文本=字符串1+字符串2+字符串3
key_message
=
key_message
+
text
#新的密文=原本的密文加入新的文本
list_message
=
list
(
key_message
)
#把列表key_message转换成字符串
list_message
.
insert
(
6
,
noise
)
#把新的元素加入到列表里
result_message
=
""
.
join
(
list_message
)
#将序列以指定字符串连成一个新的字符串
print
(
result_message
)
#显示结果
diy4.py
View file @
de8c54f3
...
@@ -5,15 +5,19 @@ key = "abcdefgh使用编程实现位移替换加密,制作密码机关真是
...
@@ -5,15 +5,19 @@ key = "abcdefgh使用编程实现位移替换加密,制作密码机关真是
# 要加密语句
# 要加密语句
message
=
"诺依,周末一起去看动漫展吧!"
message
=
"诺依,周末一起去看动漫展吧!"
key_message
=
""
key_message
=
""
noise
=
"dahkjcnkjcgyuzg"
#干扰字符随意写
# 请使用私钥key,对message进行加密
# 请使用私钥key,对message进行加密
for
i
in
range
(
len
(
message
)):
for
i
in
range
(
len
(
message
)):
a
=
message
[
i
]
str1
=
message
[
i
]
b
=
random
.
choice
(
key
)
str2
=
random
.
choice
(
key
)
c
=
random
.
choice
(
key
)
str3
=
random
.
choice
(
key
)
d
=
a
+
b
+
c
text
=
str1
+
str2
+
str3
key_message
=
key_message
+
d
key_message
=
key_message
+
text
print
(
key_message
)
list_message
=
list
(
key_message
)
message1
=
list
(
key_message
)
list_message
.
insert
(
5
,
noise
)
message1
.
insert
(
random
.
randint
(
0
,
len
(
message1
)),
"¥
%
……&*$
%
_*^&
%
(
%
^"
)
result_message
=
""
.
join
(
list_message
)
message2
=
""
.
join
(
message1
)
print
(
result_message
)
print
(
message2
)
\ No newline at end of file
print
(
key_message
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment