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
f2c5a26c
authored
Apr 18, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
1c197d62
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
str.py
str.py
0 → 100644
View file @
f2c5a26c
# #diy2
# message = "诺依,周末一起去看动漫展吧!"
# # 请对message进行遍历,取出所有元素
# for i in message:
# print(i)
# #diy3
# message = "诺依,周末一起去看动漫展吧!"
# # 请使用索引的知识,取出message所有元素(不用遍历的方式)
# i=0
# for i in range(len(message)):
# print(message[i])
#diy4
import
random
# 私钥
key
=
"abcdefgh使用编程实现位移替换加密,制作密码机关真是太好玩了哈哈!"
# 要加密语句
message
=
"诺依,周末一起去看动漫展吧!"
key_message
=
""
# 请使用私钥key,对message进行加密
for
i
in
range
(
len
(
message
)):
a
=
message
[
i
]
#对应索引的元素
b
=
random
.
choice
(
key
)
#随机抽取字符中的元素 [支持索引的元素序列choice都可以抽取]
c
=
random
.
choice
(
key
)
#存储到变量中
text
=
a
+
b
+
c
key_message
=
key_message
+
text
print
(
key_message
)
#二次加密
message1
=
list
(
key_message
)
#强转为列表
message1
.
insert
(
random
.
randint
(
0
,
len
(
message1
)),
"¥
%
……&*$
%
_*^&
%
(
%
^"
)
#插入到随机位置,索引范围为[0,列表长度]
message2
=
""
.
join
(
message1
)
#str.join()将列表里的元素用某种字符连接,括号里是列表名
print
(
message2
)
\ No newline at end of file
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