Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
WMS_AutoTest
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
胡洪 Hope Hu
WMS_AutoTest
Commits
99018fcd
Commit
99018fcd
authored
Mar 12, 2021
by
Missv4you
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
h
parent
aa4c2429
Pipeline
#6947
canceled with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
41 deletions
+0
-41
main.py
main.py
+0
-41
No files found.
main.py
deleted
100644 → 0
View file @
aa4c2429
from
Crypto.Cipher
import
AES
from
binascii
import
b2a_hex
,
a2b_hex
# 如果text不足16位的倍数就用空格补足为16位
def
add_to_16
(
text
):
if
len
(
text
.
encode
(
'utf-8'
))
%
16
:
add
=
16
-
(
len
(
text
.
encode
(
'utf-8'
))
%
16
)
else
:
add
=
0
text
=
text
+
(
'
\0
'
*
add
)
return
text
.
encode
(
'utf-8'
)
# 加密函数
def
encrypt
(
text
):
key
=
'9999999999999999'
.
encode
(
'utf-8'
)
mode
=
AES
.
MODE_CBC
iv
=
b
'qqqqqqqqqqqqqqqq'
text
=
add_to_16
(
text
)
cryptos
=
AES
.
new
(
key
,
mode
,
iv
)
cipher_text
=
cryptos
.
encrypt
(
text
)
# 因为AES加密后的字符串不一定是ascii字符集的,输出保存可能存在问题,所以这里转为16进制字符串
return
b2a_hex
(
cipher_text
)
# 解密后,去掉补足的空格用strip() 去掉
def
decrypt
(
text
):
key
=
'9999999999999999'
.
encode
(
'utf-8'
)
iv
=
b
'qqqqqqqqqqqqqqqq'
mode
=
AES
.
MODE_CBC
cryptos
=
AES
.
new
(
key
,
mode
,
iv
)
plain_text
=
cryptos
.
decrypt
(
a2b_hex
(
text
))
return
bytes
.
decode
(
plain_text
)
.
rstrip
(
'
\0
'
)
if
__name__
==
'__main__'
:
e
=
encrypt
(
"hello world"
)
# 加密
d
=
decrypt
(
e
)
# 解密
print
(
"加密:"
,
e
)
print
(
"解密:"
,
d
)
\ 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