Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-cicd
csst-dag
Commits
4aaeaae9
Commit
4aaeaae9
authored
Jun 11, 2025
by
BO ZHANG
🏀
Browse files
add hash module
parent
aaac8bca
Changes
1
Hide whitespace changes
Inline
Side-by-side
csst_dag/hash.py
0 → 100644
View file @
4aaeaae9
import
hashlib
import
random
import
string
from
astropy.time
import
Time
def
generate_sha1_from_time
(
verbose
=
False
):
"""
根据当前时间生成 SHA-1 哈希值,并添加随机字符串确保唯一性
Returns
-------
Tuple:
(时间戳, 随机字符串, SHA-1哈希值) 元组
"""
# 获取当前毫秒级时间戳(ISO格式)
timestamp
=
Time
.
now
().
isot
# 生成40个随机字母和数字
random_str
=
""
.
join
(
random
.
choices
(
string
.
ascii_letters
+
string
.
digits
,
k
=
40
))
# 将时间戳和随机字符串组合
combined_str
=
f
"
{
timestamp
}
_
{
random_str
}
"
# 生成 SHA-1 哈希
sha1
=
hashlib
.
sha1
()
sha1
.
update
(
combined_str
.
encode
(
"utf-8"
))
sha_value
=
sha1
.
hexdigest
()
if
verbose
:
return
timestamp
,
random_str
,
sha_value
else
:
return
sha_value
if
__name__
==
"__main__"
:
# 生成并输出结果
for
i
in
range
(
3
):
timestamp
,
random_str
,
sha
=
generate_sha1_from_time
(
verbose
=
True
)
print
(
"当前时间: "
,
timestamp
)
print
(
"随机字符串: "
,
random_str
)
print
(
"SHA-1 哈希: "
,
sha
)
print
(
"-"
*
50
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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